From: Joel VanderWerf Date: 2007-02-09T16:40:51+09:00 Subject: Re: How to "pass" the current binding's block to some other method? Ezra Zygmuntowicz wrote: > > On Feb 8, 2007, at 4:33 PM, Lyle Johnson wrote: > >> On 2/8/07, Joel VanderWerf wrote: >> >>> Does this help? >>> >>> class Foo >>> def try(x, y, z) >>> # ... do some other stuff first ... >>> yield self if block_given? >>> end >>> >>> alias old_try try >>> def try(hash) >>> old_try(hash[:x], hash[:y], hash[:z]) do >>> yield self if block_given? >>> end >>> end >>> end >>> >>> Foo.new.try({}) do puts "trying" end >> >> Ah, yes, that ought to do the trick too. Thanks! >> > > > def try(x, y, z) > # ... do some other stuff first ... > yield self if block_given? > end > > alias old_try try > > def try(hash) > old_try(hash[:x], hash[:y], hash[:z], &yield) > end > > > try( :a => 'foo') { puts 'hi' } Cool, &yield is new to me! But the OP wanted the following to work too, I think: try( :a => 'foo') and this will raise a LocalJumpError in this case... -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407