赞 | 68 |
VIP | 397 |
好人卡 | 580 |
积分 | 22 |
经验 | 311270 |
最后登录 | 2022-3-9 |
在线时间 | 4033 小时 |
Lv3.寻梦者 (版主) …あたしは天使なんかじゃないわ
- 梦石
- 0
- 星屑
- 2208
- 在线时间
- 4033 小时
- 注册时间
- 2010-10-4
- 帖子
- 10779
|
本帖最后由 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. |
评分
-
查看全部评分
|