Skip to content

Instantly share code, notes, and snippets.

@stretchkennedy stretchkennedy/either.rb

Last active Aug 29, 2015
Embed
What would you like to do?
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
You can’t perform that action at this time.