Joel VanderWerf
2/9/2007 7:41:00 AM
Ezra Zygmuntowicz wrote:
>
> On Feb 8, 2007, at 4:33 PM, Lyle Johnson wrote:
>
>> On 2/8/07, Joel VanderWerf <vjoel@path.berkeley.edu> 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