Skip to content

Instantly share code, notes, and snippets.

@ukazap
Created January 11, 2019 01:50
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 ukazap/09ec4794cb75dd590a032efb2a50bef1 to your computer and use it in GitHub Desktop.
Save ukazap/09ec4794cb75dd590a032efb2a50bef1 to your computer and use it in GitHub Desktop.
class Array
def my_map
self.reduce([]) do |new_array, element|
new_array.push(yield(element))
end
end
end
[1, 2, 3].my_map { |x| x * 2 }
#=> [2, 4, 6]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment