我有一個小麻煩在下面的示例跟蹤自:紅寶石跟蹤自陣列#內部的每個
# a simple class
class Foo; end
# open the Class class to add an instance method
class Class
# breakpoint 1 - self is equal to Class right here, I get why
puts self
# usage: Foo.some_method(1,2,3)
def some_method(*args)
# breakpoint 2 - when we call Foo.some_method(*args)
# self is equal to Foo, and once again I understand why
puts self
args.each do |arg|
# breakpoint 3 - self is still equal to Foo, even though we are calling each
# on an explicit receiver (an array called args)
puts self
end
end
end
那麼如何來自我當我打電話args數組上each
不會改變?我的印象是,自我總是等於接收者,這肯定會是數組。
啊,這使得感覺,詞彙範圍init?謝謝。 – stephenmurdoch 2013-05-08 01:00:20
@stephenmurdoch:好的。 – Linuxios 2013-05-08 01:01:29