Project1

标题: 关于实例对象的工作方法? [打印本页]

作者: 冷峻逸    时间: 2015-10-23 18:39
提示: 作者被禁止或删除 内容自动屏蔽
作者: taroxd    时间: 2015-10-23 19:16
Could you describe your problem in English and ruby? I cannot understand your Chinese.
作者: 冷峻逸    时间: 2015-10-23 19:27
提示: 作者被禁止或删除 内容自动屏蔽
作者: 枫の叶    时间: 2015-10-23 19:39
直接哈希啊,可以随便储存,随便赋值的啊!
作者: taroxd    时间: 2015-10-23 19:44
本帖最后由 taroxd 于 2015-10-23 19:45 编辑
冷峻逸 发表于 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.
作者: 冷峻逸    时间: 2015-10-23 19:56
提示: 作者被禁止或删除 内容自动屏蔽




欢迎光临 Project1 (https://rpg.blue/) Powered by Discuz! X3.1