From: Robert Dober Date: 2008-08-29T06:43:48+09:00 Subject: Re: Please don't flame me...why is there no "++" in Ruby again ? On Thu, Aug 28, 2008 at 11:25 PM, Joel VanderWerf wrote: > John Pritchard-williams wrote: >> >> There's must be very good simple reason why there is no 'x++' method >> Ruby right? >> >> Just generally interested why there isn't.... >> >> I did check my Ruby books by the way, but they just "unlike C there is >> no ++ operator in Ruby...." :) > > In ruby, operators are methods and they operate on objects, not on > variables. ... and as Integers are immutable ++ cannot change the underlying object. One could define ++ if one wanted, but it can only work on mutable objects class MyInteger def initialize int; @int = int end define_method "++" do @int += 1 end def to_s; @int.to_s end end m = MyInteger.new 41 puts m m.send "++" puts m Cheers Robert -- http://ruby-smalltalk.blogspot.com/ There's no one thing that's true. It's all true. -- Ernest Hemingway