L
L7
Based on the following snippet:
File.open(name).each { |line|
case line
when /not found/, /^[gBbTi]/
next
when /^S/
# start or stop condition
when /^I/
# iteration indicator
else
# actual data
end
}
In the first when, (/not found/, /^[gBbTi]/) is there any benefit in
setting up the statement in either of the following ways?
when /^[gBbTi]/, /not found/
Put the short circuit one first (expected to happen more often than
'not found')
OR
when /^g/, /^B/, /^b/, /^T/, /^i/, /not found/
Separate each operation into it's own portion of the test (ordered
by expected frequency)
I guess this is really a question of 'how does ruby handle the multiple
arguments to a case statement?'.
Are they taken in order or all compiled to a single expression before
ever being evaluated?
Thanks for any insight.
File.open(name).each { |line|
case line
when /not found/, /^[gBbTi]/
next
when /^S/
# start or stop condition
when /^I/
# iteration indicator
else
# actual data
end
}
In the first when, (/not found/, /^[gBbTi]/) is there any benefit in
setting up the statement in either of the following ways?
when /^[gBbTi]/, /not found/
Put the short circuit one first (expected to happen more often than
'not found')
OR
when /^g/, /^B/, /^b/, /^T/, /^i/, /not found/
Separate each operation into it's own portion of the test (ordered
by expected frequency)
I guess this is really a question of 'how does ruby handle the multiple
arguments to a case statement?'.
Are they taken in order or all compiled to a single expression before
ever being evaluated?
Thanks for any insight.