From: Austin Ziegler Date: 2002-07-02T07:42:48+09:00 Subject: Re: is this the way it should work? newbie problem... On Tue, 2 Jul 2002 07:30:23 +0900, MIcha wrote: >Hi, > >that seems not to work: (it' ported from perl to ruby:-) > >x = max_x if --x == 0; > >the variable x is never decremented. >why? Ruby doesn't have ++ or --. For incrementing, the succ method is the preferred way, but (at least according to Pickaxe) there is no corresponding prev method. You can simulate it with the modifications below. Note that I am still having to do assignment because Fixnum is an immediate value (you can't do self -= amt like you could in other cases). class Integer def dec(amt = 1) self - amt end def inc(amt = 1) self + amt end end p 5.dec # => 4 p 5.dec(3) # => 3 p 5.inc # => 6 p 5.inc(3) # => 8 max_x = 50 x = 2 x = x.dec x = max_x if (x = x.dec) == 0; p x -austin -- Austin Ziegler, austin@halostatue.ca on 2002.07.01 at 18.32.35