-
-
Save havenwood/743065a10a1c1796f8245b1befcf9f72 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
class Array | |
def function_map(function) | |
each_with_object [] do |item, result| | |
result << function.call(item) | |
end | |
end | |
end | |
[1, 2, 3].function_map ->(n) { n.to_s * 2 } | |
#=> ["11", "22", "33"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment