Skip to content

Instantly share code, notes, and snippets.

@mecampbellsoup
Created September 27, 2013 05:00
Show Gist options
  • Select an option

  • Save mecampbellsoup/6724372 to your computer and use it in GitHub Desktop.

Select an option

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.
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