Created
July 31, 2012 00:59
-
-
Save sionide21/3212396 to your computer and use it in GitHub Desktop.
Regex game regression tester
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Regexen | |
def initialize(a={}) | |
a.default_proc = proc { |h,k| [] } | |
@good = a[:good] | |
@bad = a[:bad] | |
end | |
def good=(r) | |
@good << r | |
end | |
def bad=(r) | |
@bad << r | |
end | |
def to_s | |
"Regexen.new good: #{@good}, bad: #{@bad}" | |
end | |
def check(r) | |
@good.find {|b| not r.match(b)} or @bad.find {|b| r.match(b) } | |
end | |
end |
Whoops. Good catch. I always initialize it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ruby hashes don't clone default values, so if you initialize with
Regexen.new()
then@good.equal? @bad
.I don't know how to make a pull request for gists, so I just forked and modified it.