我想写一个继承Bignum类的代码,我不知道如何获得Bignum的值
class BigNum
# the metod should check if the a divide BigNum
def divide?(a)
# how to get the value of Bignum
self %a == 0
end
end发布于 2012-01-08 17:56:10
由于Ruby允许您扩展现有类,因此您不必创建自己的类:
class Bignum
def divide?(a)
self %a == 0
end
end这会添加一个方法divide吗?添加到现有的(内置)类Bignum。
发布于 2012-01-08 17:54:19
类名是Bignum而不是BigNum。
https://stackoverflow.com/questions/8776621
复制相似问题