冷峻逸 发表于 2015-10-23 19:27
about how 实例对象 works
long long ago,I think ruby makes a variable in the ram.
but now, i think ...
Take ```b = A.new``` as an example.
A.new returns the *pointer* of a C *struct* that represented the instance. The struct includes the class of the instance, so that when we call ```A.new.a```, Ruby is able to find the method in A, the class of ```A.new```.
When we assign A.new to variable ```b```, Ruby inserts the reference to a table in the *binding*. The table is just like a hash, and what Ruby has done is like ```table["b"] = the pointer of A.new```. As we call ```b.a``` later, Ruby finds the pointer referenced by ```b```, gets the C struct that represents it, and thus knows all information about the object, such as its class and instance variables.