Skip to content

Instantly share code, notes, and snippets.

@joecorcoran
Last active March 13, 2017 20:31
Show Gist options
  • Save joecorcoran/1dd69d67edf10991c87ed90febe7d63a to your computer and use it in GitHub Desktop.
Save joecorcoran/1dd69d67edf10991c87ed90febe7d63a to your computer and use it in GitHub Desktop.
# Define the method #each (without using Enumerable#each) so that
# the following prints three lines:
# def each ...
# ...
# end
rgb = ['red', 'blue', 'green']
each(rgb) do |c|
puts "I like #{c}!"
end
# Solution below, no peeking :)
def each(arr, &block)
for x in arr do
block.call(x)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment