On Tuesday, April 22, 2003, at 08:02 PM, Ian Macdonald wrote:
>
> My question is: since Kernel#id gives the internal Ruby identifier of
> the object in question, something that does not change, why does this
> method allow the setting of the id of the object? Is there a valid
> reason to write to the id?
>

It doesn't. When you write, you're writing to a variable. When you 
read, well.. it depends:

class Dave
   def my_id
     99
   end

   def play
     puts my_id      #=> 99
     my_id = 10
     puts my_id      #=> 10
     puts self.my_id  #=> 99
   end
end

Dave.new.play


This is an area where Ruby is just a tad too accommodating. It would be 
nice if -w warned that the interpretation of a symbol changed in the 
same scope (in this case from a method call to a variable).

Cheers

Dave