On Fri, Mar 28, 2003 at 06:54:58AM +0900, daniel wrote: > my code in ruby looks like this... > -- > i=0 > arr_stuff.each { > |a| > $tk_listbox_stuff.insert( i, a.to_s) > i += 1 > } > -- > > I really love the c++ style with > ++i > or > i++ > > Is there a smart way to do such things in ruby? In the above example there's an even smarter way: arr_stuff.each_with_index { |a,i| $tk_listbox_stuff.insert( i, a.to_s) } Neat, huh? You can't do "i++" or "i.succ!" because in Ruby numbers are immutable objects, and variables always hold references to objects. When 'i' contains a reference to the number 3, say, you can't send a message to the number 3 saying "turn yourself into 4". All you can do is change 'i' to point to a new object, the number 4. The only way you can change what a local variable points to is via assignment: i = ... some object ... Hence: i = (i+1), or i += 1 which expands to the same thing. Regards, Brian.