S
Sebastian Friedrich
i'm currently learning Ruby. So, while learning about code blocks and
yields i wanted to put my freshly acquired knowledge to the test and
(just to see if i understood correctly) write my own simple each method
for Arrays. so i did:
class Array
def each
for x in self
yield(x)
end
end
end
But running it gives me SystemStackError: stack level too deep. It works
fine when i rename it, so i guess it's just Ruby not appreciating my
fine work or somehow making sure i don't introduce flagrant overwrites
to built-in methods??? Anybody feels like enlightening me on how this
works? Thanks.
yields i wanted to put my freshly acquired knowledge to the test and
(just to see if i understood correctly) write my own simple each method
for Arrays. so i did:
class Array
def each
for x in self
yield(x)
end
end
end
But running it gives me SystemStackError: stack level too deep. It works
fine when i rename it, so i guess it's just Ruby not appreciating my
fine work or somehow making sure i don't introduce flagrant overwrites
to built-in methods??? Anybody feels like enlightening me on how this
works? Thanks.