From: Tony Arcieri Date: 2010-11-30T07:30:40+09:00 Subject: Re: Correct use of block --001636c5975dbc5be90496389ee5 Content-Type: text/plain; charset=ISO-8859-1 On Mon, Nov 29, 2010 at 11:50 AM, Martin wrote: > 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? You can do rsp = nil t=time_method do rsp = Net::HTTP.get_response(URI.parse(url).host, URI.parse(url).path) end Since rsp was bound outside the scope of a block, it gets closed over, so rebinding it will alter the outer variable (unlike Python's lambdas, or most other languages for that matter) You might consider using Ruby's built-in "benchmark" library as well: require "benchmark" rsp = nil puts Benchmark.measure do rsp = Net::HTTP.get_response(URI.parse(url).host, URI.parse(url).path) end -- Tony Arcieri Medioh! A Kudelski Brand --001636c5975dbc5be90496389ee5--