Module specific metric methods for Numeric


#1

Hi,

I love ruby for it flexibility and ability to adapt, but I encountered a
problem which I don’t have the answer for.
Different modules may use a different metric base. Sketchup for examples
thinks that 4 actually means 4 inch while another system might think it
is 4 meter. It would be nice to be able to get rid of these issued by
having specific Numeric methods which can change in a module. The test
script I wrote is:


#2

Something went wrong and the message was submitted before I was
finished, so here the rest:

The test script I wrote is:
class Numeric
def cm
self*2.54
end
end
puts “4.cm = #{4.cm}”
module Test
class Numeric

            def cm
                    self*0.1
            end
    end

end

class Tc
include Test
def initialize
puts “4.cm => #{4.cm}”
end
end
t = Tc.new
puts “4.cm = #{4.cm}”
this results in:
4.cm = 10.16
4.cm => 10.16
4.cm = 10.16

Replacing class Numeric with class Object::Numeric will result in:
4.cm = 10.16
4.cm => 0.4
4.cm = 0.4

while the actual result that I aim for is:
4.cm = 10.16
4.cm => 0.4
4.cm = 10.16

Does anyone knows the answer to this one? Or an even better approach?

Many thanks,

Benjamin