----- Original Message ----- From: "Robert Dober" <robert.dober / gmail.com> To: "ruby-talk ML" <ruby-talk / ruby-lang.org> Sent: Sunday, June 03, 2007 6:38 PM Subject: Re: [QUIZ] FizzBuzz (#126) > Sergey it is your fault if I cannot sleep ;), is this more readable ? relax, Robert, nobody hurt :) > module Enumerable > def change(to, &blk) > map{ |x| blk.call(x) ? to : x } > end > end # module Enumerable > > puts (1..100).change(:FizzBuzz){ |x| x%15 == 0 }.change(:Fizz){ |x| > x%3 == 0 rescue false}.change(:Buzz){ |x| x%5 == 0 rescue false } hard to make formal conclusions - there are no formal requirements, nor context is well defined, I can share my own opinion and potential concerns only: - yes, indeed, this solution is more readable, compared to your Array-nested-tricky-indexed original solution; - clear functional decomposition simplifies understanding, maintenance; - it is easily expandable thanks to chain processing; btw: I prefer different name for Enumerable method, ex: substitute_if; Not so attractive in this solution: - run-time/memory inefficient: each item is generates 4 times; - memory inefficient: generates and stores in memory 4*original array (ex: not well suited for 10**9 length array); - can not be adopted for stream processing (read - process - print); - 'rescue' is for exceptional processing, should be avoided in normal control flow; Sergey Volkov