所以我明白你不应该直接子类为Fixnum,Float或Integer,因为它们没有#new方法。使用DelegateClass似乎工作,但它是最好的方式?任何人都知道这些类没有#new的原因是什么?红宝石子类别Fixnum
我需要它的行为像一个Fixnum,但有一些额外的方法类,我想能够通过self
从类中引用它的值,例如:
class Foo < Fixnum
def initialize value
super value
end
def increment
self + 1
end
end
Foo.new(5).increment + 4 # => 10
告诉我们你真正想要做什么(最终目标),我们会尽力告诉你最好的方法。我不认为在这里分类是合适的。 – 2009-07-08 02:05:51
更新了问题。 – cloudhead 2009-07-08 02:12:34