Created
September 27, 2013 05:00
-
-
Save mecampbellsoup/6724372 to your computer and use it in GitHub Desktop.
Replica of Ruby's Array#each method. Appropriately dubbed "my_each"... :) Throwing in my_collect for shits and giggles.
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_each | |
| i = 0 | |
| while i < self.length | |
| yield(self[i]) | |
| i += 1 | |
| end | |
| self | |
| end | |
| def my_collect | |
| results = [] | |
| self.my_each do |i| | |
| results << yield(i) | |
| end | |
| results | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment