Q:

Why can't I change the value of self?

How come I'm allowed to change "self" this way:
self.map! {|x| x*2}

Or this way:
self.replace(self.map {|x| x*2})

But not this way:
self = self.map {|x| x*2}

Why doesn't Ruby allow me to change the object that the "self" variable points to, but does allow me to change the object's attributes?

A:

Not an answer, just a clue.
a=[1,2]
=>[1,2]
a.object_id
=>2938

a.map!{|x| x*2}
=>[2,4]
a.object_id  # different data but still the same object
=>2938

a.replace(a.map {|x| x*2})
=>[4,8]
a.object_id  # different data but still the same object
=>2938

a = a.map{|x| x*2} # .map will create a new object assign to a 
=>[8,16]
a.object_id  #different object
=>2940   

You can't change your self to another one.

