# Module specific metric methods for Numeric

**URL:** <https://www.ruby-forum.com/t/module-specific-metric-methods-for-numeric/156816>\
**Category:** Ruby\
**Created:** [January 3, 2009, 12:16pm UTC](https://www.ruby-forum.com/t/module-specific-metric-methods-for-numeric/156816 "2009-01-03T12:16:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![bterkuile](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e68b1a/32.png) [@bterkuile](https://www.ruby-forum.com/u/bterkuile)\
**Post date:** [January 3, 2009, 12:16pm UTC](https://www.ruby-forum.com/t/module-specific-metric-methods-for-numeric/156816/1 "2009-01-03T12:16:54Z")

</div>

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:

---

<div class="post-metadata">

**Author:** ![bterkuile](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e68b1a/32.png) [@bterkuile](https://www.ruby-forum.com/u/bterkuile)\
**Post date:** [January 3, 2009, 12:22pm UTC](https://www.ruby-forum.com/t/module-specific-metric-methods-for-numeric/156816/2 "2009-01-03T12:22:26Z")

</div>

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
