We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.
Thanks for posting this. I'm still baffled at how to find out anything about the specific usage .map(&:method) in anything like official docs. I've looked for it at docs.ruby-lang.org and at ruby-doc.org, and both say that that Enumerable#map takes no arguments at all (same for Array#map). How would anyone ever find out that something like this even exists?
thanks!
nice!
[].map(&MyClass.new) # why did it even do anything? Isn't .map suppose to call the (&MyClass.new) for each element of [] this array.. It is empty so I was thinking it will call (&MyClass.new) 'nil' times
Map will call the passed proc 0 times. Prefixing the MyClass instance returned by .new with a & calls the to_proc method on that MyClass instance and the proc returned from that function is then passed to map as a parameter. It happens before map is invoked so map can't short circuit it to avoid creating the proc.
Thanks for this. It helped a lot.
Awesome explanation!
Can I call a method that takes arguments? "[...].each(&:method, arg1, arg2)" ?
Curious for this too.
Thanks for your explanation
just WOW!
Thanks, this was such a nice explanation, I needed a refresher!
Amazing and simple explanation, thank you!
Fantastic explanation!