-2
position = 14
position = position - position%3
=> 12

That code above works, but I am loath to reference position three times. Is there an equivalent ++ for what I am attempting to do above? I envision something like position =-%3.

I can't find anything in the ruby-docs. Anyone?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Theta
  • 175
  • 8

1 Answers1

1

Alternatively (just for some variety):

position = (position / 3) * 3

This assumes position holds an integer, not a float (like 14.0). In which case you could do (position.to_i / 3) * 3.

lurker
  • 56,987
  • 9
  • 69
  • 103