From: ts Date: 2002-09-21T21:22:33+09:00 Subject: Re: Creating a method given a block >>>>> "G" == Gray, Jeff writes: G> If you're 'eval'-averse, you could replace the class_eval with a yes, 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 a = Extendable.new a.build(:foo) { |str| puts "foo:#{str}" } a.build(:noo) { |str1, str2| puts "noo:#{str1};#{str2}" } a.foo("bar") #-> "foo:bar" a.noo("baz", "blah") #-> "noo:baz;blah" b = Extendable.new b.foo("aa") pigeon% pigeon% b.rb foo:bar noo:baz;blah ./b.rb:16: undefined method `foo' for # (NameError) pigeon% Guy Decoux