Strange Array#each Ruby behaviour
Posted
by
with a dot.
on Stack Overflow
See other posts from Stack Overflow
or by with a dot.
Published on 2012-07-01T20:25:55Z
Indexed on
2012/07/01
21:16 UTC
Read the original article
Hit count: 164
ruby
The question is a bit vague, but I am not really sure why this happens:
I have the following code:
p user.room.users.length
user.room.users.each {|usr| puts "b" }
user.room.users.each {|usr| puts "a"; usr.enter(Room[Config::entrance]) }
which outputs:
5
b
b
b
b
b
a
a
a
I also made User#enter count how many times it's been called and it returns 3
! I am completely baffled by this behaviour. I doubt the code within User#enter is the cause, but if someone thinks it might be relevant I can provide it (I don't want to clutter the question unnecessarily).
Edit
If it's relevant I am using ruby-1.9.3-p125
© Stack Overflow or respective owner