Ruby:变量是 ruby​​ 中的对象吗? [英] Ruby: Is variable is object in ruby?

查看:28
本文介绍了Ruby:变量是 ruby​​ 中的对象吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说 ruby​​ 中的一切都是对象.面试时回答说变量是对象,面试官说NO.有人知道真相吗?

I heard that everything in ruby is object. I replied in an interview that a variable is an object, and the interviewer said NO. Anybody know the truth?

推荐答案

在 ruby​​ 中,一切都是对象"基本上是正确的.

"In ruby, everything is an object" is basically true.

但更准确地说,任何可以分配给变量或从方法返回的值都是对象.变量是一个对象吗?并不真地.变量只是一个对象的名称(也称为指针"),它允许您在内存中定位它并使用它做任何事情.

But more accurately, I would say that any value that can be assigned to a variable or returned from a method is an object. Is a variable an object? Not really. A variable is simply a name of an object (also known as a "pointer") that allows you locate it in memory and do stuff with it.

shajin = Person.new()

在这个片段中,我们有一个变量 shajin,它指向一个对象(person 类的一个实例).变量只是对象的标识符,而不是对象本身.

In this snippet, we have a variable shajin, which points to an object (an instance of the person class). The variable is simply the identifier for an object, but is not the object itself.

我认为这是一个棘手的问题.最终,面向对象是人类理解复杂程序的特征,但计算机本身并不是面向对象的.向下钻取足够多的层,对象不再以任何语言存在.

I think it was a trick question. Ultimately object orientation is feature for humans to understand complex programs, but computers are not object oriented themselves. Drill down enough layers and objects cease to exist in any language.

所以也许更公平地说:在 ruby​​ 中,一切重要都是一个对象".

So perhaps it's more fair to say: "In ruby, everything important is an object".

这篇关于Ruby:变量是 ruby​​ 中的对象吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆