I have a rather old code with a very long case/menu, which
acts on user-supplied input. I already fear that I will have
to rewrite it heavily, but before I start I thought I go and
ask here.

A typical line of that case/menu looks like so:


when "foobar","foo","f"
  do_something()

Obviously, I did want the user be able to type foobar, foo, or f
and have the same method or code invoked. Lateron I realized that
this was not optimal, one better approach would have been this:

alias_listing:
  foo, f -> pointing to foobar, which then invokes do_something()

(The real scenario is a bit more complicated, but the code above
serves as a good trivial example.)

How to solve the above? Using a big hash which keeps all
aliases and only leave a single entry per when line, like so?

# process input here and check on aliases, and then replace
# them pointing to "foobar"?
when "foobar"
  do_something
when "blafoo"
  do_something_else
-- 
Posted via http://www.ruby-forum.com/.