On Mon, Oct 15, 2012 at 1:27 PM, li shoubo <lists / ruby-forum.com> wrote:
> can you give me more details? Or it is a rule that I can not use yield
> in define_method method to define a new one?

You got it.  But you can use Proc#call instead:

irb(main):013:0> String.send(:define_method, :foo) {|a, &b| b.call(a +
length())}
=> #<Proc:0x802b6c4c@(irb):12 (lambda)>
irb(main):014:0> s="bar"
=> "bar"
irb(main):015:0> s.foo(10) {|x| p x}
13
=> 13

Kind regards

robert

-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/