Ruby methods return the last evaluated value

Note that a does not return.

[1] pry(main)> def m
[1] pry(main)*   a = 1
[1] pry(main)*   b = 2
[1] pry(main)*   a
[1] pry(main)*   b #The last evaluated b is the return value of the method
[1] pry(main)* end
=> :m
[2] pry(main)> m
=> 2 #The previously evaluated a is not returned.

Recommended Posts

Ruby methods return the last evaluated value
9 Corresponds to the return value
[Ruby] What happens if the method self is used as the return value?
Store the AWS SDK return value in DynamoDB
[Ruby] Difference between puts and return, output and return value
Ruby Learning # 15 Methods
To get Ruby Silver at the last minute
About Ruby methods
I want to get the value in Ruby
[Ruby / Rails] Set a unique (unique) value in the class
In Ruby, methods with? Do not always return true/false.
About Ruby instance methods
Minimum value (ruby edition)
Ruby variables and methods
[Ruby] methods, instance methods, etc ...
Ruby Learning # 16 Return Statement
About the [ruby] operator
Try Java return value
Let the code speak rather than comment (Maybe return value)
Determine that the value is a multiple of 〇 in Ruby