From: Nasir Khan Date: 2007-08-27T11:15:01+09:00 Subject: how to check for block in an evaled method? ------=_Part_178465_27140608.1188180895451 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Consider the snippet - class B def set B.class_eval do define_method(:a) do |arg| if block_given? yield else "hello" end end end end end The intention is that block_given? would tell me if the new method a() is invoked with a block or not. Now I run this irb(main):057:0* y = B.new => # irb(main):059:0> y.set => # irb(main):060:0> y.a (irb):45: warning: multiple values for a block parameter (0 for 1) from (irb):60 => "hello" Now if I use with a block irb(main):061:0> y.a {"bye"} (irb):45: warning: multiple values for a block parameter (0 for 1) from (irb):61 => "hello" Oops doesnt work ! Actually the block is being evaled when the method is being created - irb(main):062:0> y.set {"bye"} => # irb(main):063:0> y.a (irb):45: warning: multiple values for a block parameter (0 for 1) from (irb):63 => "bye" I get that. But the question is, is there a way to check for a block and then yield in a defined method, as was my naive intention? Thanks Nasir ------=_Part_178465_27140608.1188180895451--