3 ms·
Know your closures: Ruby's blocks, procs, and lambdas
- banister 14y ago``` If methods were first-class functions, this would work — > method_a would return method_b, which would then execute when x() was called. This doesn't work because Ruby methods aren't objects. ``` Seems the OP is just confused by syntax? we use obj.method(:method_a) instead of obj.method_a, i dont see why requiring a different syntax changes the semantics on this point.
- cdavaz 14y agoIn your example: ampersandy(10) do |x| x + 10 end # => 10 Actually the result should be '20' as well.
- nfm 14y agoThis post deserved so many more upvotes! Fantastic summary, and explained lots of things I didn't quite get really well. Bookmarked.