I am trying to implement Integer#times, but don't know how to know the value of an Integer object. So I am doing it like this:
class Integer
def times
n = (self.next) -1
x = 1
while x <= n
yield(x)
x += 1
end
end
end
I am using (self.next) -1 to get the value of the object:) I know it is not the right way of doing it. How to get the value of the Integer object?
x = 1; x.equal?(x.to_i)istrue. In fact, the definition ofInteger#to_iisstatic VALUE int_to_i(VALUE num) { return num; }(equivalent todef to_i; self; endin Ruby).