From: Andrew Wagner Date: 2010-11-30T03:57:57+09:00 Subject: Re: Correct use of block --0016e6d58cfc511194049635a6d0 Content-Type: text/plain; charset=UTF-8 On Mon, Nov 29, 2010 at 1:50 PM, Martin wrote: > Hi > > I've been using Python for years, but looking into Ruby and rails. > > Is the following a sensible way to use Ruby blocks? > > def time_method() > t1=Time.now > if block_given? > result=yield() > end > return Time.now-t1,result > end > > t,rsp=time_method do > Net::HTTP.get_response(URI.parse(url).host, URI.parse(url).path) > end > > My problem is that both time_method and get_response returns a value > that i need. Should i use a closure instead of the above? > > Thanks. > > Personally, I think this is quite reasonable. I might rename the method something like "call_and_time", and I'd probably leave off the empty parens after the method name and the yield. --0016e6d58cfc511194049635a6d0--