I have the following block in a ruby script:
for line in allLines
line.match(/aPattern/) { |matchData|
# Do something with matchData
}
end
If /aPattern/ does not match anything in line, will the block still run? And if not, is there a way I can force it to run?
The answer is no, the match block will not be run if the match does not suceed. However,
foris generally not used in Ruby anyways,eachis more idiomatic, like:Note,
=~is a regex match operator.