I’m using named rexeg capture groups and my case statement works with match, but it gives me data that I don’t want. When I run the code below it only works to match one statement. Where am I going wrong?
File::open(file).lines do |line|
case
when line.scan(regex1) then puts line.scan(regex1)
when line.scan(regex2) then puts line.scan(regex2)
when line.scan(regex3) then puts line.scan(regex3)
end
end
end
caseexecutes the first true-expresion.If you have multiple checks, where each check can be true, you should use mutliple
if-statements.I think the following version is a bit more flexible and efficient: