У меня небольшие проблемы отслеживания себя в следующем примере:Рубин отслеживания себя внутри массива # каждый
# 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
Так как прийти себя не меняется, когда я звоню each
на массиве ARGS? У меня создалось впечатление, что я всегда равен получателю, который, несомненно, будет массивом?
Ahh, что делает смысл, лексический обзор? Благодарю. – stephenmurdoch
@stephenmurdoch: Конечно. – Linuxios