Skip to content

Instantly share code, notes, and snippets.

@sarogers
Created November 14, 2013 17:18
Show Gist options
  • Save sarogers/7470647 to your computer and use it in GitHub Desktop.
Save sarogers/7470647 to your computer and use it in GitHub Desktop.
# Complete the "my_each" method.
def my_each
end
describe "my_each" do
it "should let us iterate over a collection of objects and do stuff" do
students = [
{ name: 'Rachael' },
{ name: 'Josephina'},
{ name: 'Benedict'}
]
my_each(students) do |student|
student[:enrolled] = true
end
students[0][:enrolled].should == true
students[1][:enrolled].should == true
students[2][:enrolled].should == true
end
it "should return the original collection" do
array = %w(foo bar baz qux)
my_each(array) do |word|
word.upcase
end.should == %w(foo bar baz qux)
end
it "should not execute the block given an empty collection" do
o = Object.new
o.should_not_receive(:methods)
my_each([]) do |n|
o.methods
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment