I have some code that uses a counter. In certain circumstances, I have
to subtract from the counter variable. I thought I could simple do this:
my_variable -1
and my_variable would simply get reduced by one (the same way we use the
=+1)
However, this is what I see:
1.9.3-p392 :001 > x = true
=> true
1.9.3-p392 :002 > y = false
=> false
1.9.3-p392 :003 > @headcount = 4
=> 4
1.9.3-p392 :004 > if x
1.9.3-p392 :005?> @headcount -3
1.9.3-p392 :006?> elsif y
1.9.3-p392 :007?> @headcount -1
1.9.3-p392 :008?> end
=> 1
1.9.3-p392 :009 > puts @headcount
4
=> nil
If I use @headcount = @headcount -1 the subtraction works. But I didn’t
think I had to do this… am I confused about that point?
Wayne