在 Ruby 中,“接收者”做什么? 参考?
我正在阅读一份关于具有接收器的方法的文档。 什么是接收器?
I'm reading a document that talks about a method having a receiver. What's a receiver?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 Ruby(以及受 SmallTalk 启发的其他语言)中,对象被认为是发送和接收“消息”。
在 Ruby 中,Object 作为一切事物的基类,有一个 send 方法: Object.send 例如:
在这两种情况下,k 都是“hello”消息的接收者。
In Ruby (and other languages that take inspiration from SmallTalk) objects are thought of as sending and receiving 'messages'.
In Ruby, Object, the base class of everything, has a send method: Object.send For example:
In both of these cases k is the receiver of the 'hello' message.
在最初的 Smalltalk 术语中,“对象”上的方法被称为对象消息(即,您没有调用对象 foo 上的方法,而是向对象 foo 发送了一条消息)。 所以 foo.blah 正在发送“blah”消息,“foo”对象正在接收该消息; “foo”是“blah”的接收者。
In the original Smalltalk terminology, methods on "objects" were instead refered to as messages to objects (i.e. you didn't call a method on object foo, you sent object foo a message). So foo.blah is sending the "blah" message, which the "foo" object is receiving; "foo" is the receiver of "blah".
之前的对象。
将调用方法 xy 视为“将指令 y 发送到对象 x”。
这是smalltalk 的思维方式,当您了解Ruby 的一些更高级的功能时,它会对您很有帮助。
the object before the .
think of calling a method x.y as saying "send instruction y to object x".
it's the smalltalk way of thinking, it will serve you well as you get to some of Ruby's more advanced features.