You can’t do it directly on the case statement but you can store the
options elsewhere and use splat for the case syntax:
OPTIONS = [['abc', 'def'], ['ghi', 'h']]
case x
when *OPTIONS[0]
first_option = OPTIONS.detect { |a| a.include?(x) }[0]
do_this
when *OPTIONS[1]
do_that
end
Andrew V.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.