by btakita · 17y ago · 0 comments
The more standard way goes from top to bottom. The lambda method requires the reader to go to the bottom of the statement, then to the top and downward. It requires the writer to remember the idiom and it's a barrier to newer developers.
I also don't see the win in doing this either. Sure, somebody can forget to set the return value, but you can also screw up with the other idiom. That part seems like a wash to me.
* edit - Grammatical corrections and reformatting.
returning [1] do |numbers|
numbers << 2
numbers += [3]
end
And that's all you see in your source code. RewriteRails rewrites that into: lambda do |numbers|
numbers << 2
numbers += [3]
numbers
end.call([1])
And that's what the ruby interpreter sees. But you need never look at the "ugly" rewritten version, just what you wrote.