Previn Lin wrote in post #1131257:
> Can we do like the way below? But how to process the Regular express in
> our case?
>
> def eat(fruit_code)
>   fruit_type =
>     case fruit_code
>      when 'a'
>        Apple
>      when 'b'
>       Banana
>      when 'c'
>       Coconut
>      when 'o'
>       Orange
>     end
> end
>
> =>
>
> FRUIT_TYPES=
>   { 'a' => Apple, 'b' => Banana, 'c' => Coconut, 'o' => Orange }.
>     freeze
>
> def eat(fruit_code)
>   fruit_type = FRUIT_TYPES[fruit_code]
> end

If you want to do this with Regexp here's one option:

types = {
  astro: 'astro',
  core: 'coretools',
  fm_shell: 'fm',
  formality: 'fm',
  gca_shell: 'gcas',
  xa: 'xa'
}
toolName = cmd.match( /\A(#{ types.keys.join('|') })\z/ ) { |s| 
types[s.captures.first.to_sym] }

-- 
Posted via http://www.ruby-forum.com/.