34,333
edits
Changes
→Returning a Value from a Function
It is important to note that a method can return one, and only one value or object. If you need to return multiple values, consider placing the results in an array and returning the array.
== Ruby Method Aliases ==
Ruby allows a method to be aliased, thereby creating a copy of a method with a different name (although invoking the method with either ultimately calls the same object). For example:
<pre>
irb(main):001:0> def multiply(val1, val2 )
irb(main):002:1> result = val1 * val2
irb(main):003:1> return result
irb(main):004:1> end
=> nil
alias docalc multiply
=> nil
docalc( 10, 20 )
=> 200
multiply( 10, 20 )
=> 200
</pre>