Friday, December 25, 2009

In Ruby Arrays are also Queues

In Ruby it is safe to add an element to the end of an array during iteration.

a = [0,1,2]
a.each do |b|
  puts b
  if 1 == (b % 2)
    a << a.last + 1
  end
end
Ranges as are not arrays.
a = (0..2)

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

Links to this post:

Create a Link

<< Home