On Mon, Dec 14, 2009 at 3:23 PM, Roger Pack <rogerpack2005 / gmail.com> wrote:

> >> "abcd"[0..2] = 'ggg'
> => "ggg"
>
> What is going on here, anybody have any ideas?
>

Ruby lets you invoke #[]= on literals.  They then go immediately out of
scope and will be garbage collected, I assume.  #[]= will always return the
value on the RHS.

Perhaps this clears things up:

=> "abcd"
>> x[0..2] = 'ggg'
=> "ggg"
>> x
=> "gggd"

So that's what would happen if you used a variable instead of a literal.
What you're doing isn't much different from:

{:foo => 42}[:foo] = 'ggg'

-- 
Tony Arcieri
Medioh! A Kudelski Brand