我正在尝试实现Integer#times,但是不知道如何知道Integer对象的值。所以我这样做是这样的:
class Integer
def times
n = (self.next) -1
x = 1
while x <= n
yield(x)
x += 1
end
end
end
我正在使用(self.next)-1获取对象的值:)我知道这不是正确的方法。如何获取Integer对象的值?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句