[Ruby] Difference between puts and return, output and return value

puts only outputs. On the other hand, return only returns the return value. puts cannot be used to pass values. return has no output.

puts.rb


def greet 
   puts "Hello"
end
@example = greet
@example =>nil

return.rb


def greet2
   return "Hello"
end
@example2 = greet2
@example =>"Hello"

Is it a miso to use properly whether or not to pass the value? I don't have enough study about the return value

Recommended Posts

[Ruby] Difference between puts and return, output and return value
Note: Difference between Ruby "p" and "puts"
[Ruby] Difference between print, puts and p
Difference between puts and print
[Ruby] Difference between get and post
[Ruby] Difference between is_a? And instance_of?
[Android] Difference between finish (); and return;
Difference between Ruby instance variable and local variable
Difference between "|| =" and "instance_variable_defined?" In Ruby memoization
Difference between vh and%
Difference between i ++ and ++ i
[Ruby] Difference between receiver and object. Differences between Ruby objects and JS objects
About the difference between classes and instances in Ruby
Difference between product and variant
Difference between redirect_to and render
[Java] Difference between == and equals
Rails: Difference between resources and resources
Difference between redirect_to and render
Difference between CUI and GUI
Difference between variables and instance variables
Difference between class and instance
Difference between bundle and bundle install
Difference between ArrayList and LinkedList
Difference between render and redirect_to
Difference between List and ArrayList
[Ruby] Difference between match / scan
Difference between .bashrc and .bash_profile
Difference between StringBuilder and StringBuffer
Difference between render and redirect_to
Difference between render and redirect_to
About the difference between "(double quotation)" and "single quotation" in Ruby
[Ruby] About the difference between 2 dots and 3 dots of range object.
The difference between programming with Ruby classes and programming without it
Difference between render method and redirect_to
Difference between interface and abstract class
Difference between == operator and equals method
[Java] Difference between Hashmap and HashTable
[Terminal] Difference between irb and pry
JavaServlet: Difference between executeQuery and executeUpdate
[Rails] Difference between find and find_by
[JAVA] Difference between abstract and interface
Difference between Thymeleaf @RestController and @Controller
Difference between Stream map and flatMap
[Java] Difference between array and ArrayList
Difference between string.getByte () and Hex.decodeHex (string.toCharaArray ())
[Java] Difference between Closeable and AutoCloseable
[Java] Difference between StringBuffer and StringBuilder
[Java] Difference between length, length () and size ()
[rails] Difference between redirect_to and render
[Ruby] Maybe you don't really understand? [Difference between class and module]
[Ruby] Difference between symbol variables and character string variables. About the difference between [: a] and ['a'].
Easy to understand the difference between Ruby instance method and class method.
Difference between final and Immutable in Java
[Memo] Difference between bundle install and update
Difference between pop () and peek () in stack
The content of the return value of executeBatch is different between 11g and 12c
[For beginners] Difference between Java and Kotlin
Difference between isEmpty and isBlank of StringUtils
Ruby print puts p printf output method
Ruby methods return the last evaluated value
The difference between puts and print in Ruby is not just the presence or absence of line breaks