2008/3/10, Trans <transfire / gmail.com>:
> In the case of limited options, like the following example, which is
>  better?
>
>  class String
>
>   def align(direction. spacing)
>     case direction
>     when :left
>       ...
>     when :right
>       ...
>     when :center
>       ...
>     end
>   end
>
>  OR
>
>   def align_left(spacing)
>     ...
>   end
>
>   def align_right(spacing)
>     ...
>   end
>
>   def align_center(spacing)
>     ...
>   end
>
>  Thanks,

The general wisdom suggests to favor multiple methods over a single
method that changes behavior based on arguments.  They are easier to
implement (all the switching and conditions are not needed) but most
of all the code is more modular on the interface level.  Note that you
can still use a single method to implement behavior internally if that
is more efficient / easier.

Unfortunately I do not have a pointer to a more thorough discussion handy...

Kind regards

robert

-- 
use.inject do |as, often| as.you_can - without end