class Array def one_by_one for i in 0..size yield(self[i]) end puts end end
arr = [1,3,5,7,9]
arr.one_by_one {|h| print (h*h)}
写的实例代码
报错如下:
19254981one_by_one.rb:12:in block in <main>': undefined method
*' for nil:NilClass (NoMethodError)
from one_by_one.rb:4:in block in one_by_one'
from one_by_one.rb:3:in
each'
from one_by_one.rb:3:in one_by_one'
from one_by_one.rb:12:in
好奇,为啥*没有了?