From: Rick DeNatale Date: 2008-01-12T10:08:51+09:00 Subject: Re: .times loop returns the number? On 1/11/08, John Joyce wrote: > Ruby blocks always return the last value returned in the block. true but.. > if you simply do this: > > x.times do |x| > code_here_using_x > puts "cat" > end > > the block will return "cat" But the whole expression won't. irb(main):001:0> irb(main):001:0> 5.times {|i| "a"} => 5 irb(main):002:0> 5.times {|i| puts "cat"} cat cat cat cat cat => 5 And puts "cat" doesn't return "cat" irb(main):004:0> puts "cat" cat => nil On the other hand Integer#times is documented to return the integer: qri Integer#times ---------------------------------------------------------- Integer#times int.times {|i| block } => int ------------------------------------------------------------------------ -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/