Created
September 2, 2013 08:26
-
-
Save rskelley9/6410501 to your computer and use it in GitHub Desktop.
My Map method.
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(&block) | |
self.each_index do |i| | |
yield (self[i] = block.call(self[i])) | |
end | |
end | |
end | |
a = [1,2,3,4] | |
puts a.my_map{|i| i -= 1} == a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment