Skip to content

Instantly share code, notes, and snippets.

@burke
Last active December 15, 2015 08:08
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 burke/5228225 to your computer and use it in GitHub Desktop.
Save burke/5228225 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment