on-internet
← Community

Using Named Captures with regex match in Ruby's case...when?

Stack Overflow ·

I want to parse user input using named captures for readability. When they type a command I want to capture some params and pass them. I'm using RegExps in a case statement and thus I can't assign the return of /pattern/.named_captures. Here is what I would like to be able to do (for example): while command != "quit" print "Command: " command = gets.chomp case command when /load (?<filename>\w+)/ load(filename) end end

Comments

Sign in or sign up to comment and upvote.

No comments yet.