Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@jlnr 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