Forum: Ruby Extract all case when entries

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Robert H. (Guest)
on 2014-07-20 18:29
Hi:


consider


def foo(i)
  case i
  when 'foo','bar',
       'bla'
    call_this
  when 'yo'
    call_ok
  end
end

Is there a simple way to programmatically get all entries of a given
case menu?

So I would get an array like:

['foo','bar','bla','yo']

?
Joel P. (Guest)
on 2014-07-20 21:03
The only way I could think of to do that would be to read and parse the
text file containing the code. Then it's a bit of regex to isolate the
case statement and pull out the entries.
This topic is locked and can not be replied to.