21

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'

Charles
  • 50,943
  • 13
  • 104
  • 142
Hable
  • 313
  • 1
  • 2
  • 5
  • I've searched throughly before posting this, could you please explain how is it duplicate of the post mentioned – Hable Aug 15 '13 at 08:36

1 Answers1

41

just use:

when *STORE_CODES

instead of :

when 'code1', 'code2'... 'code_n'
Muntasim
  • 6,689
  • 3
  • 46
  • 69
  • 3
    For those curious, `*` is a splat operator which (among other things) turns arrays into comma separated strings. Good info on this here: https://endofline.wordpress.com/2011/01/21/the-strange-ruby-splat/ – Adam Grant Jan 18 '16 at 22:41