Created
April 5, 2016 17:31
-
-
Save mindplace/b1db4e6e441846254d39ba1631a8a685 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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