From: Alex Young Date: 2007-11-27T09:24:28+09:00 Subject: Re: Most elegant way to do this? rbysamppi@gmail.com wrote: > Are there any more elegant, concise, pithy, and more Rubyish ways of > doing this? > > def roll(number_of_dice) > sum = 0 > number_of_dice.times do > sum += rand(5).next > end > sum > end > > Thanks in advance! > The Incredible Inevitable Inject: def roll(number_of_dice) (0...number_of_dice).inject(0){|m,r| rand(5)+m} end -- Alex