On Mon, Oct 15, 2012 at 1:27 PM, li shoubo <[email protected]> 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/

-- You received this message because you are subscribed to the Google Groups 
ruby-talk-google group. To post to this group, send email to 
[email protected]. To unsubscribe from this group, send email 
to [email protected]. For more options, visit this 
group at https://groups.google.com/d/forum/ruby-talk-google?hl=en

Reply via email to