Return to Snippet

Revision: 13414
at April 23, 2009 07:22 by wdso


Initial Code
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)

Initial URL

                                

Initial Description
Extracted from "The Ruby Way: Solutions and Techniques in Ruby Programming."

Initial Title
Iterator shortcut using symbols

Initial Tags

                                

Initial Language
Ruby