Skip to content

Instantly share code, notes, and snippets.

@havenwood
Last active July 31, 2019 18:56
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 havenwood/743065a10a1c1796f8245b1befcf9f72 to your computer and use it in GitHub Desktop.
Save havenwood/743065a10a1c1796f8245b1befcf9f72 to your computer and use it in GitHub Desktop.
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