Skip to content

Instantly share code, notes, and snippets.

@sionide21
Created July 31, 2012 00:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sionide21/3212396 to your computer and use it in GitHub Desktop.
Save sionide21/3212396 to your computer and use it in GitHub Desktop.
Regex game regression tester
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
@davidh-raybeam
Copy link

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.

@sionide21
Copy link
Author

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