Skip to content

Instantly share code, notes, and snippets.

@hahcho
Created March 17, 2014 21:36
Show Gist options
  • Save hahcho/9608896 to your computer and use it in GitHub Desktop.
Save hahcho/9608896 to your computer and use it in GitHub Desktop.
class ArrayMatcher
attr_reader :matcher
def initialize(*matcher)
@matcher = matcher
end
def ===(other)
matcher.zip(other).all? {|pair| pair.first === pair.last}
end
end
x = ['a', 'b']
case x
when ArrayMatcher.new(/a/, /c/)
print 1
when ArrayMatcher.new(/a/, /b/)
print 2
else
print 3
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment