K
Kevin Börgens
Hi!
How to restart a "each" iteration when the iterated array is changed? I do
it like this
changed=false
while (changed)
changed=false
array.each {|e|
if (today_is_christmas)
array=array+=["Hello santa claus"]
changed=true
end
}
Is there a more elegant way to do this?
Second question:
why is this not allowed
#show me the first n letters of the alphabet
('a'...'a'+gets.to_i).each{|e| puts e }
How to do it the right way?
Thanks in advance,
Kevin
How to restart a "each" iteration when the iterated array is changed? I do
it like this
changed=false
while (changed)
changed=false
array.each {|e|
if (today_is_christmas)
array=array+=["Hello santa claus"]
changed=true
end
}
Is there a more elegant way to do this?
Second question:
why is this not allowed
#show me the first n letters of the alphabet
('a'...'a'+gets.to_i).each{|e| puts e }
How to do it the right way?
Thanks in advance,
Kevin