From: Lou Vanek Date: 2006-02-08T04:53:58+09:00 Subject: Re: About Extending Systax 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