Skip to content

Instantly share code, notes, and snippets.

@benjamintanweihao
Forked from banister/pry_gist.rb
Created March 19, 2014 00:18
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 benjamintanweihao/9632995 to your computer and use it in GitHub Desktop.
Save benjamintanweihao/9632995 to your computer and use it in GitHub Desktop.
class Blah
def add(x, y)
x + y
end
end
# => nil
class Symbol
def call(*args, &block)
->(o) { o.send(self, *args, &block) }
end
end
# => nil
ary = Array.new(5) { Blah.new }
# => [#<Blah:0x007fd0ff1119d0>,
# #<Blah:0x007fd0ff1119a8>,
# #<Blah:0x007fd0ff111980>,
# #<Blah:0x007fd0ff111958>,
# #<Blah:0x007fd0ff111908>]
ary.map(&:add.(5, 6))
# => [11, 11, 11, 11, 11]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment