From: CHubas Date: 2007-06-04T14:55:28+09:00 Subject: Re: FizzBuzz (#126) On Jun 1, 7:28 am, Ruby Quiz wrote: > The three rules of Ruby Quiz: Interesting quiz, as usual. I don't really have experience applying for jobs, but my own experience tells me that when writing code, you should write it for others to read it, change it, manage it and/or throw it away. The first question that jumps into my mind is: why would a job interviewer wanted me to write me such a program? What the heck is a 'FizzBuzz'? Probably is a company secret. To me, it looks like a little useless noise coming from somewhere. # Class that takes numbers and transforms them into a symbol # specified for the user class UselessSoundMaker attr_accessor :sounds def initialize(args) @sounds = args end def add_sounds(args) @sounds.update(args) end def display(range = 1..100) for number in range if (multiples = @sounds.keys.select{|m| number % m == 0}).empty? puts number else puts multiples.sort.collect{|m| @sounds[m]}.join end end end end fizzbuzz = UselessSoundMaker.new(3 => 'Fizz', 5 => 'Buzz') fizzbuzz.display foobar = UselessSoundMaker.new(3 => 'Foo', 4 => 'Bar', 5 => 'Baz') foobar.display(1..50) beepbeep = UselessSoundMaker.new(10 => "\a") beepbeep.display(1..100) Thanks again for the quizes. Ruben Medellin. __________________________________________ Dictionary is the only place that success comes before work. - Vince Lombardi