Skip to content

Instantly share code, notes, and snippets.

@banister
Created March 14, 2014 16:44
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 banister/9551558 to your computer and use it in GitHub Desktop.
Save banister/9551558 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]
@jlnr
Copy link

jlnr commented Apr 17, 2014

.( looks so wrong. Why not &:add.bind(5, 6)? C++ flavoured ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment