From: "Gray, Jeff" Date: 2002-09-24T04:51:27+09:00 Subject: RE: Creating a method given a block > From: ts [mailto:decoux@moulon.inra.fr] > >>>>> "G" == Gray, Jeff writes: > > G> 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. ;^) > G> 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