/ Published in: Ruby
Extracted from "The Ruby Way: Solutions and Techniques in Ruby Programming."
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
class Symbol def to_proc proc {|obj, *args| obj.send(self, *args) } end end # map takes a block, & causes the interpreter to invoke to_proc on given symbol # symbol is passed as message to the object beeing processed # in other words, this is a short way of writing: # list = words.map {|x| x.capitalize } list = words.map(&:capitalize)