[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
[Ruby] Difference between print, puts and p
[Android] Difference between finish (); and return;
Difference between "|| =" and "instance_variable_defined?" In Ruby memoization
Difference between vh and%
Difference between i ++ and ++ i
Difference between .bashrc and .bash_profile
Difference between StringBuilder and StringBuffer
Difference between render and redirect_to
The difference between programming with Ruby classes and programming without it
Ruby learning 6
Ruby settings 1
2020/10/3 Noon output
Ruby learning 1
2020/10/3 Morning output
Drill (self-made)
2020/10/3 Morning output
2020/10/3 Noon output
[ruby] drill output
[Ruby] Difference between puts and return, output and return value
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
Easy to understand the difference between Ruby instance method and class method.
[ruby] drill output
Output triangle in Ruby
2020/10/5 Morning output
Ruby learning 2
Ruby learning 6
Ruby settings 1
2020/10/3 Noon output
Ruby learning 1
2020/10/3 Morning output
Drill (self-made)
[Ruby] Difference between puts and return, output and return value
Difference between final and Immutable in Java
[Java] Difference between Closeable and AutoCloseable
About the difference between irb and pry
Difference between EMPTY_ELEMENTDATA and DEFAULTCAPACITY_EMPTY_ELEMENTDATA in ArrayList
Differences between Ruby strings and symbols [Beginner]
[Java] Difference between Intstream range and rangeClosed
Difference between int and Integer in Java
Ruby methods return the last evaluated value
[Ruby] Difference between puts and return, output and return value
About Ruby methods
I want to get the value in Ruby
Minimum value (ruby edition)
[Ruby] methods, instance methods, etc ...
Try Java return value
[Rails] Difference between create method and new + save method
[Java] Difference between "final variable" and "immutable object"
Ruby How to convert between uppercase and lowercase
Ruby and Gem
What is the difference between skip and pending? [RSpec]
[Swift] UITextField taught me the difference between nil and ""
[Java beginner] Difference between length and length () ~ I don't know ~
[ruby] drill output
[ruby] drill output
Ruby calorie calculation output
Output triangle in Ruby
Ruby problem ⑦
2020/10/5 Morning output
Ruby learning 2
Ruby learning 6
Ruby settings 1
2020/10/3 Noon output
Ruby learning 1
2020/10/3 Morning output
Drill (self-made)
[Ruby] Difference between puts and return, output and return value