I am doing a problem at Rubymonk where I have to test if an array is ‘nil’ before doing an operation (adding to items in the array but that is not really relevant to the question). I notice, however, when I do
ary.nil? ? nil : ary.map {|x,y=0| x + y }
The code works but if I do
ary.nil? ? **return** nil : ary.map {|x,y=0| x + y }
it does not.
However, if I do
if ary.nil?
**return **nil
else
ary.map {|x,y=0| x + y }
end
Why does ‘**return **nil’ work in one instance and not the other? (bold used only for emphasis throughout)
I would have expected ‘return’ to work in both instances.