by rubyist5eva · 5y ago · 0 comments
One thing that is cool about the .to_proc shorthand though is, for example, you have a method
def square_it(x); x * 2; end;
people tend to write an enumeration that uses it like
items.map {|i| square_it i }
but you can actually write it like this
items.map(&method(:square_it))
So not only can you write shorthands to methods on the object itself, you can write shorthands to other methods and "automagically" pass the item as its argument. Nifty stuff.
No comments yet.