Last active
December 15, 2015 08:08
-
-
Save burke/5228225 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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