For example, I have the following code.
str = 'delay loss duplicate etc'
case str
when /delay/ then
puts 'delay'
when /loss/ then
puts 'loss'
end
I want give.
delay
loss
Is it possible in ruby not break all next conditions 开发者_运维百科when the first coincidence?
I'm not sure case
is really what you want here.
str = 'delay loss duplicate etc'
regex = { /delay/ => 'delay', /loss/ => 'loss' }
regex.each { |r, s| puts s if str =~ r }
If you want another regex, just add a key/value pair to the hash.
精彩评论