Skip to content

Instantly share code, notes, and snippets.

@Joseworks
Forked from stevegraham/1.rb
Created December 29, 2017 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Joseworks/6b6d31bc4b9e0c6616e3f97338ca4ae0 to your computer and use it in GitHub Desktop.
Save Joseworks/6b6d31bc4b9e0c6616e3f97338ca4ae0 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