Ruby中的方法和消息有什么区别?

时间:2016-04-11 15:41:21

标签: ruby

什么是“引擎盖下”的差异?有什么实际差异?

与用户的观点有什么不同吗?

我知道您可以使用1) def list = ["a", "b", "c", "d"] list.findAll({println(it)}) 2) def list = ["a", "b", "c", "d"] list.collect({println(it)}) 3) def list = ["a", "b", "c", "d"] list.grep({println(it)}) 来定义方法,但是您可以定义一条消息吗?

1 个答案:

答案 0 :(得分:2)

When you send a message to an object, the object will (usually) respond by executing a method with the same name as that message.

You cannot define messages. You just send them.