From: Colin Bartlett Date: 2009-12-16T14:56:51+09:00 Subject: Re: what does this do? On Tue, Dec 15, 2009 at 3:31 PM, Roger Pack wrote: > On Mon, Dec 14, 2009 at 3:23 PM, Roger Pack > wrote: > >> "abcd"[0..2] = 'ggg' > => "ggg" > What is going on here, anybody have any ideas? I hesitate to add to the above replies, but I might learn something, so: IRB class Q def z=( v ) ; @y = 42 ; end def y() ; @y ; end end #=> nil q = Q.new #=> # q.y #=> nil q.z = 113 #=> 113 q.y = #=> 42 q #=> # From Programming Ruby, 1st Edition, 2000, page 76: http://ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html An assignment statement sets the variable or attribute on its left side (the lvalue) to refer to the value on the right (the rvalue). It then returns that value as the result of the assignment expression. "abcd"[0..2] = 'ggg' is an assignment expression, and the rvalue is "ggg", so that's what's returned. Whilst usually (but not always, as in the Q example above) the assignment "sets" the lvalue target to the rvalue, that's (sort of) "irrelevant" to what the assignment expression returns?