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
···
--
Posted via http://www.ruby-forum.com/.