我正在阅读ruby 编程语言。在本书的第 251 页,有以下代码:
countdown = Object.new # A plain old object
def countdown.each # The each iterator as a singleton method
yield 3
yield 2
yield 1
end
countdown.extend(Enumerable) # Now the object has all Enumerable methods
print countdown.sort # Prints "[1, 2, 3]"
我不明白。数字 ( 1
, 2
, 3
) 是从哪里来的?yield
方法接收它们。但那些不是成员变量,是吗?