On 3 June 2014 15:57, Arup Rakshit <aruprakshit / rocketmail.com> wrote:

>
>
>
>         if @@names[c.to_sym]
>           @@names[c.to_sym]
>         else
>           raise ArgumentError, "Not a color nane"
>         end
>
> The above can be written also -
>
> @@names.fetch(c.to_sym, ArgumentError.new("Not a color nane"))
>
>
>
Not quite, since #fetch doesn't raise the default. But you could use
either of the following:

    @@names.fetch(c.to_sym) {|k| raise ArgumentError, "Not a color name" }
    @@names[c.to_sym] or raise ArgumentError, "Not a color name"

I wrote it my way first because, originally, I was going to start with `if
c =~ /#.../`, so the name lookup was the second if-statement, and it seemed
more natural to write it that way.



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