如何理解 Ruby 中的发送方和接收方? [英] How to understand sender and receiver in Ruby?

查看:32
本文介绍了如何理解 Ruby 中的发送方和接收方?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现很难理解 Ruby 中发送方和接收方的实际含义.它们一般是什么意思?到目前为止,我只是将它们理解为方法调用和获取其返回值的方法.但是,我知道我的理解还远远不够.谁能给我一个关于 Ruby 中发送方和接收方的具体解释?

I find it hard to understand the actual meaning of sender and receiver in Ruby. What do they mean in general? So far I simply understand them as the method call and the one that takes its return value. However, I know my understanding is far from enough. Can anyone give me an specific explanation of sender and receiver in Ruby?

推荐答案

面向对象的一个​​核心概念是消息传递和早期概念化,大量借鉴了计算的 Actor 模型.Alan Kay 创造了面向对象一词并发明了第一批面向对象语言 SmallTalk 之一,他 表示遗憾使用一个将重点放在对象而不是消息上的术语,他认为这是一个更强烈的想法.

A core concept in Object Orientation is messaging and early conceptualization borrowed much from the Actor Model of computation. Alan Kay, the guy who coined the term Object Oriented and invented one of the first OO languages SmallTalk, has voiced regret at using a term which put the focus on objects instead of on messages, which he considered the stronger idea.

在谈论消息时,消息有一个自然的发送者"和接收者".发送方是调用方法的对象,接收方是调用方法的对象.在 Ruby 中,如果调用方法时没有明确命名对象,则会将方法名称及其参数作为消息发送到默认接收器 self.

When talking about a message, there's a natural "sender" and "receiver" of the message. The sender is the object which invokes a method, the receiver is the object whose method is invoked. In Ruby, if one calls a method without explicitly naming an object, that sends the method name and its args as a message to the default receiver self.

在 OO 中,调用"、调用方法"和发送消息"是等效的概念.类似地,被调用"、调用自己的方法"和接收消息"是等价的.

In OO, "making a call", "invoking a method", and "sending a message" are equivalent concepts. Similarly "being called", "having one's method invoked", and "receiving a message" are equivalent.

这篇关于如何理解 Ruby 中的发送方和接收方?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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