Hi all,
I’m trying to figure out a case concerning the Refinements using an
extension from another refinement.
I would like to submit an example to get some clarification.
here is the code about a sample file ‘test_refinement_all_in_one.rb’:
module MyFloatExtension
refine Float do
def to_my_value
self.to_s
end
end
end
using MyFloatExtension
module MyTimeExtension
refine Time do
def to_my_time_value
self.to_s
end
def to_my_value
self.to_f.to_my_value
end
end
end
using MyTimeExtension
now=Time.now
puts now.to_my_time_value
puts now.to_my_value
The output of code execution is:
test_refinement_all_in_one.rb:2: warning: Refinements are experimental,
and the behavior may change in future versions of Ruby!
2013-04-03 16:17:41 +0200
test_refinement_all_in_one.rb:17:in to_my_value': undefined method
to_my_value’ for 1364998661.0880127:Float (NoMethodError)
from test_refinement_all_in_one.rb:26:in `’
The error is the same even when module are implemented in different
individual files.
My question is if I made any mistakes in the implementation: there is a
way to correct this error or it’s a limitation of the current
implementation of Refinements ?
Thanks in advance,
Enrico