public
Last active

  • Download Gist
fmap.rb
Ruby
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
require 'binding_of_caller'
 
module Enumerable
 
def my_map(sym)
[].tap do |r|
each do |e|
r << e.send(sym)
end
end
end
 
def fmap(sym)
m = binding.of_caller(1).method(sym)
[].tap do |r|
each do |e|
r << m.(e)
end
end
end
 
end
 
if __FILE__ == $0
 
def add3(x)
x + 3
end
 
puts ["hello", "world"].my_map(:upcase)
 
puts [1,2].fmap(:add3)
end

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.