On 3 June 2014 06:17, Wayne Conrad <kf7qga / gmail.com> wrote:

> Making a habit of checking type is indeed not the way to Ruby
> Zen, but it is occasionally useful to write code that can take a
> duck _or_ a zebra.
>
> Imagine a method that will take either a Color object, or a
> string or symbol with the color name:
>
>     def scribble(color)
>       color = Color.lookup(color) unless color.is_a?(Color)
>       ...
>     end
>
> I imagine it is for purposes such as this that the tutorial
> is teaching how to tell whether you've got a duck.
>
>
A more Ruby way might be to have Color.lookup(color) be perfectly happy to
accept a Color object. Then you'd have:

  def scribble color
    color = Color.lookup color
    ...
  end

For comparison, see Kernel#Integer and friends.

-- 
  Matthew Kerwin
  http://matthew.kerwin.net.au/