From: dblack@... Date: 2003-01-08T23:55:38+09:00 Subject: Re: Can you detect if a method takes a block argument? Hi -- On Wed, 8 Jan 2003, Martin Weber wrote: > Quick shot, suppose ruby wizards can make this still better. > > def use_block?(invoke) > catch (:block) do > eval "#{invoke} do > throw :block, true > end" > end or false > end > > pass the call you want to check along with arguments as string. > > > use_block?("print('3\n')") Don't deprive yourself of the pleasures of #puts :-) > 3 > => false > > use_block?("[1,2,3].sort") > => true I'm not sure what you gain here, since you only learn after the fact that a method had to take a block. You could call the method again... but it's very possible that the first call will have changed the program's state. I think you'd be better off with an underlying design that didn't depend on this. Can you not just document your methods so that the code that invokes them knows what to do? David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav