L
Li Chen
Hi all,
Maybe I miss something. But I am confused about method call within a
class. What is the format for that? I just copy some code segments from
the forum as follows:
module Enumerable
def each_with_index
i = 0
each do |elem|
yield elem, i
i += 1
end
end
end
class Array
def each_with_index
size.times do |i|
yield self, i
end
end
end
So
1) which one is the reciever for "each"?
2) which one is the reciever for "size"?
Do they default to self?
Thanks,
Li
Maybe I miss something. But I am confused about method call within a
class. What is the format for that? I just copy some code segments from
the forum as follows:
module Enumerable
def each_with_index
i = 0
each do |elem|
yield elem, i
i += 1
end
end
end
class Array
def each_with_index
size.times do |i|
yield self, i
end
end
end
So
1) which one is the reciever for "each"?
2) which one is the reciever for "size"?
Do they default to self?
Thanks,
Li