Ruby/Rails passing array to case

Hable picture Hable · Aug 15, 2013 · Viewed 7.7k times · Source

Here is the scenario:

case code
  when 'www', '', nil
    false
  when 'code1', 'code2'... 'code_n' # The array STORE_CODES contains all the codes 
    true
  else
    false
end

How can I use STORE_CODES directly after when instead of 'code1', 'code2'... 'code_n'

Answer

Muntasim picture Muntasim · Aug 15, 2013

just use:

when *STORE_CODES

instead of :

when 'code1', 'code2'... 'code_n'