Actually, this might be a place where you want to use a virtual class (or eigen class or whatever the name du jour for it is).
So basically, you create an instance of Chart and give it instance methods that only it and no other instance has by modifying its virtual class rather than the Chart class.
One way to get at it might be something like below using 'vclass' and extending the previous example.
class Hash
def to_xml_properties
self
end
end
class Chart
def method_missing(method,*args,&block)
STDERR.puts 'method missing!'
method_name=method.to_s
instance_variable_set '@'+method_name , {method_name => 1}
self.class.send(:attr_reader, method_name)
self.class.send(:attr_writer, method_name)
vclass = class << self; self; end
vclass.send(:define_method,'special_'+method_name) do
"special! "+method_name
end
a=self.class.send(:define_method, method_name+'_xml') do
%{<#{method_name} %s />} % instance_variable_get('@'+method_name).to_xml_properties
end
self.send(method_name)
end
end
c=Chart.new
p c.baz
p c.baz_xml
p c.baz
p c.baz_xml
p c.foo
p c.foo_xml
p c.special_baz
p c.special_foo
.
Regards,
Daniel Bush
--
Daniel Bush