Skip to content

Instantly share code, notes, and snippets.

@stretchkennedy
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stretchkennedy/3b23722a2c945c99f3ba to your computer and use it in GitHub Desktop.
Save stretchkennedy/3b23722a2c945c99f3ba to your computer and use it in GitHub Desktop.
Create a class which will be equal to any of the passed-in arguments.
# USAGE: expect(some_object).to eq either(String, 5, { this: :hash }, @something_else)
def either *objs
Class.new(Object) do
@objs = objs
def self.===(other)
@objs.reduce(false) do |memo, obj|
memo ||= JsonExpressions::Matcher.new(obj).match(other)
end
end
def self.inspect
"either(#{@objs.map(&:inspect).join(', ')})"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment