查看: 2079|回复: 5

[已经解决] 关于实例对象的工作方法?

[复制链接]
头像被屏蔽
梦石
0
星屑
88
在线时间
631 小时
注册时间
2014-8-4
回帖
3243
发表于 2015-10-23 18:39:59 | 显示全部楼层 |阅读模式
提示: 作者被禁止或删除 内容自动屏蔽
签名被屏蔽

…あたしは天

梦石
0
星屑
2308
在线时间
4033 小时
注册时间
2010-10-4
回帖
10548

开拓者贵宾

发表于 2015-10-23 19:44:07 | 显示全部楼层
本帖最后由 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.

评分

参与人数 1星屑 +100 收起 理由
丿梁丶小柒 + 100 认可答案

查看全部评分

回复

使用道具 举报

…あたしは天

梦石
0
星屑
2308
在线时间
4033 小时
注册时间
2010-10-4
回帖
10548

开拓者贵宾

发表于 2015-10-23 19:16:55 | 显示全部楼层
Could you describe your problem in English and ruby? I cannot understand your Chinese.

评分

参与人数 1星屑 +233 收起 理由
VIPArcher + 233 你居然妄图理解猴子

查看全部评分

回复

使用道具 举报

头像被屏蔽
梦石
0
星屑
88
在线时间
631 小时
注册时间
2014-8-4
回帖
3243
 楼主| 发表于 2015-10-23 19:27:33 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
签名被屏蔽
回复

使用道具 举报

梦石
0
星屑
451
在线时间
228 小时
注册时间
2015-2-23
回帖
233
发表于 2015-10-23 19:39:21 | 显示全部楼层
直接哈希啊,可以随便储存,随便赋值的啊!

点评

...  发表于 2015-10-24 08:44
a = Hash.new 这有实例又有对象啊!  发表于 2015-10-23 21:53
我是说实例对象  发表于 2015-10-23 19:52
制作XP特效,找我。
回复

使用道具 举报

头像被屏蔽
梦石
0
星屑
88
在线时间
631 小时
注册时间
2014-8-4
回帖
3243
 楼主| 发表于 2015-10-23 19:56:06 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
签名被屏蔽
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册会员

本版积分规则

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部