Hi,
today I wrote a method in my youthful levity and was wondering
about raised exceptions. The method was similar to:
def do_class_sensitive(classhandle)
case classhandle
when Array
#do somethiong…
when String
#do somethiong…
when Fixnum
#do somethiong…
else
raise "what to do with #{classhandle.name}??"
end
end
The aim was to write a class sensitive switch - but this does not
work. I could use the classname (the string) to make the switch work,
but this was not the intention. I could imagine, that inheritance is
the academic problem of the case-switch: falls a subclass of Array into
the Array-clause or into the else-clause? (if the specific subclass is
not listed in the switch).
So I want to ask: what is the expected behaviour of a class sensitive switch??
Best regards,
Matthias