为什么不能正常工作?如何在ruby中为一个模块覆盖一个类?
module Magic
class Fixnum
def div2(other)
self.to_f/other
end
alias :"/" :div2
end
end
module SomeModule
include Magic
1/4 == 0.25 #should be true in here
end
1/4 == 0.25 #should be false everywhere else
一个细节:'self.to_f'确定,但'to_f'就足够了。 –