nice

Jim Weirich wrote:

> Sam Kong wrote:
> 
>>Hi!
>>
[snip]
> 
> 
> There are several ways this could be done ... here is one:
> 
>   class TryFinally
>     def initialize(block)
>       @block = block
>     end
>     def finally
>       @block.call
>     ensure
>       yield
>     end
>   end
> 
>   def try(&block)
>     TryFinally.new(block)
>   end
> 
> Usage:
> 
>   try {
>     puts "Trying"
>     fail "oops"
>   }.finally {
>     puts "Always printed"
>   }
> 
> It is a bit little easier in Smalltalk because of the use of keywords in 
> an argument list, but still quite doable in Ruby.
> 
> --
> -- Jim Weirich