On 9/4/06, URABE Shyouhei <shyouhei / ice.uec.ac.jp> wrote:
> Hi,
>
> Calamitas wrote:
> > Well, immutable is relative:
>
> The term "immutable" is not clearly defined in Ruby.  You may surprise
> to know that even nil can be modified.
>
> a = nil
> def a.foo
>   p self
> end
> a.foo # => nil
>
>
> Matz once wrote to me there are no "strictly" immutable objects.

I know, I've tried lots of these things when I was learning Ruby, like
adding instance variables to Fixnums:

  irb(main):001:0> 1.instance_eval { @a = 1 }
  => 1
  irb(main):002:0> puts 1.instance_eval { @a }
  1
  => nil

But whatever the reason for the optimization, it unexpectedly broke
some code of mine. Sometimes I wonder if it might be interesting to
have a list of optimizations in Ruby that are (usually unexpectedly)
visible to the programmer and that programmers may want to beware of.

Peter