Skip to content

Instantly share code, notes, and snippets.

@stevegraham
Created September 20, 2012 00:25
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stevegraham/3753209 to your computer and use it in GitHub Desktop.
Save stevegraham/3753209 to your computer and use it in GitHub Desktop.
Symbol#to_proc
%w(john paul ringo george).map { |p| p.capitalize }
# => ["John", "Paul", "Ringo", "George"]
%w(john paul ringo george).map(&:capitalize)
# => ["John", "Paul", "Ringo", "George"]
class Symbol
def to_proc
Proc.new { |*args| args.shift.__send__(self, *args) }
end
end
[10, 6, 3].inject(&:*)
# => 180
class Symbol
def to_proc
Proc.new { |obj| obj.send self }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment