From: ts [mailto:decoux@moulon.inra.fr]
If you’re ‘eval’-averse, you could replace the class_eval with a
yes,
Gee, why did I think that Guy might have something to say here. ;^)
method_missing trap instead.
no
pigeon% cat b.rb
#!/usr/bin/ruby
class Extendable
def build(name, &block)
class << self; self; end.send(:define_method, name, &block)
end
end
Problem is Hal said he needed a solution that was 1.6-compatible,
therefore not relying on define_method…
Also, since the list of methods defined with ‘build’ is contained
in the keys of the @@dispatch_table, I don’t see why method_missing
would be objectionable here. The trap could still raise a
RuntimeError if the method that led to it were not one that was
initially defined with ‘build’…
Cheers,
- jeff