Skip to content

Instantly share code, notes, and snippets.

@mindplace
Created April 5, 2016 17:31
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 mindplace/b1db4e6e441846254d39ba1631a8a685 to your computer and use it in GitHub Desktop.
Save mindplace/b1db4e6e441846254d39ba1631a8a685 to your computer and use it in GitHub Desktop.
class Array
def my_map(&prc)
new = []
self.my_each{|item| new << prc.call(item)}
new
end
def my_select(&prc)
selected = []
self.my_each{|item| selected << item if prc.call(item)}
selected
end
def my_inject(&blk)
sum = self[0]
self[1..-1].my_each{|item| sum = blk.call(sum, item) }
sum
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment