Recall & Review
beginner
What does every method in Ruby return by default?
Every method in Ruby returns the value of the last evaluated expression automatically, even if you don't use the
return keyword.Click to reveal answer
beginner
Why does Ruby methods always return a value?
Ruby is designed so that methods always return a value to make code concise and expressive, allowing you to use the result of a method directly without extra steps.
Click to reveal answer
beginner
What happens if you use the
return keyword inside a Ruby method?Using
return immediately exits the method and returns the specified value, overriding the default behavior of returning the last evaluated expression.Click to reveal answer
beginner
How can you explain Ruby's method return behavior using a real-life example?
Think of a vending machine: when you press a button (call a method), it always gives you something back (returns a value), even if it’s just a message or a snack.
Click to reveal answer
beginner
Can a Ruby method return
nil?Yes, if the last evaluated expression is
nil or if the method has no expressions, Ruby returns nil by default.Click to reveal answer
What does a Ruby method return if there is no explicit
return statement?✗ Incorrect
Ruby methods automatically return the value of the last evaluated expression if no explicit
return is used.What does the
return keyword do inside a Ruby method?✗ Incorrect
Using
return exits the method immediately and returns the given value.If a Ruby method has no expressions inside, what will it return?
✗ Incorrect
When a method has no expressions, Ruby returns
nil by default.Why does Ruby always return a value from methods?
✗ Incorrect
Ruby’s design encourages concise code and method chaining by always returning a value.
Which of these is true about Ruby method returns?
✗ Incorrect
Ruby methods always return a value; if nothing else, they return
nil.Explain why Ruby methods always return a value and how this affects writing code.
Think about how Ruby treats the last line inside a method.
You got /4 concepts.
Describe what happens when you use the
return keyword inside a Ruby method.Consider how <code>return</code> changes the flow inside a method.
You got /4 concepts.