From: Moises Trovo Date: 2008-02-05T03:20:11+09:00 Subject: Re: Learn to Program, by Chris Pine ------=_Part_9192_17960499.1202149208136 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline actually ROMAN[key] and not working with numbers having a 9. On Feb 3, 2008 4:02 AM, Todd Benson wrote: > On Feb 2, 2008 8:49 PM, Todd Benson wrote: > > Actually, better production code that keeps in line with OO concepts > would be... > > > > class Integer > > ROMAN = { > > 1 => "I", > > 5 => "V", > > 10 => "X", > > 50 => "L", > > 100 => "C", > > 500 => "D", > > 1000 => "M" > > } > > > > def roman > > number, roman_string = self, "" > > ROMAN.keys.sort.reverse.each do |key| > > roman_string << (ROMAN[n] * (number/key) > > n %= key > > end > > roman_string > > end > > end > > > > #usage > > puts 2137.roman > > # => "MMCCCXVII" > > > > I'm pretty sure there were better and more thorough examples at > > http://www.rubyquiz.com/quiz22.html. > > gsub('number', 'n') on that code...and there's a missing parenthesis > ")" number/key line > > Yeah, yeah > > That's what I get for not using cut and paste :-) > > Todd > > ------=_Part_9192_17960499.1202149208136--