From: dblack@... Date: 2003-09-22T19:48:53+09:00 Subject: Re: Operator overloading Hi -- On Mon, 22 Sep 2003, Tom Felker wrote: > On Sun, 21 Sep 2003 11:29:27 -0700, dhtapp wrote: > > > Hi, > > > > I'm pretty new to Ruby, so someone may step in quickly to correct me. But > > my understanding is that, for any of the standard dyadic operators (+, -, > > etc.) the shorthand > > > > j += 1 > > > > is expanded before evaluation to: > > > > j = j + 1 > > Not quite - I think j += 1 only evaluates j once. I recall one instance > where that helped me, performance-wise. The j on the left isn't being evaluated; it's just being assigned to. So in cases with objects that can have more than one instance (like String), you get a new object: irb(main):001:0> j = "abc" => "abc" irb(main):002:0> j.id => 537889088 irb(main):003:0> j += "d" => "abcd" irb(main):004:0> j.id => 537881918 With integers you don't, of course, but it's also a case of assigning to a variable, where the variable name on the left just serves to accept the assignment (in the expanded form). David -- David Alan Black home: dblack@superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav