-1
我自己实施了each
方法。我应该在关闭该方法之前明确地返回self
。这是我的代码:为什么我的代码返回接收器?
module Enumerable
def my_each
for i in self
yield i
end
#self
end
end
[1,2,3,4].my_each {|x| x + 1} # => [1,2,3,4]
为什么代码仍然会返回即使我没有明确的最后一行返回self
接收器?
因为'对于i在self'返回'self'。 – mudasobwa