Skip to content

Instantly share code, notes, and snippets.

@rdammkoehler
Created May 3, 2012 02:37
Show Gist options
  • Save rdammkoehler/2582623 to your computer and use it in GitHub Desktop.
Save rdammkoehler/2582623 to your computer and use it in GitHub Desktop.
Stuff I'm doing
def good_or_bad lines, patterns
lines.zip(patterns).all? { |(line, pattern)|
not(line.match(pattern).nil?)
}
end
def report lines, patterns
if good_or_bad(lines, patterns)
puts "all lines match the given patterns in order"
else
puts "one or more lines do not match the given pattern"
end
end
report [ "line1", "line2", "line3" ], [ "pattern1", "pattern2", "pattern3" ] #=> one or more lines do not match the given pattern
report [ "line1", "line2", "line3" ], [ "^line", "2$", "line3" ] #=> all lines match the given patterns in order
@rdammkoehler
Copy link
Author

tx, to Magnus Stahre for the tip on all?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment