Florian Gross wrote:

<snip>
> And this will also work and require less repetition:
> 
> puts case key.strip
>    when "c": "Synopsis"
>    when "s": "Category"
>    ...
> end
> 

Actually the code has less duplication, this was just an example. But why
doesn't this work:
def keyToName(key)
        case key.strip
....
                when "h" "Element handlers"
                when "a" "See also"
                else "Unknown key"
        end
end

puts keyToName("a")
puts keyToName('a')
It gives "Unknown key" twice, instead of "See also" at least once.

> Though I wonder if you're not better of with a Hash:
> 
> puts({
>    "c" => "Synopsis",
>    "s" => "Category",
>    ...
> }[key.strip])

That sounds nice, is that code faster?

Thanks for your help
-- 
"May the source be with you"