Created
August 25, 2014 07:00
-
-
Save stretchkennedy/69a4a508ba02cb275a8f to your computer and use it in GitHub Desktop.
For use with https://github.com/chancancode/json_expressions. Allows you to write either(FooClass, BarClass). Useful if you're expecting nils.
This file contains hidden or 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
module JsonExpressionHelper | |
def either *klasses | |
Class.new(Object) do | |
@klasses = klasses | |
def self.===(other) | |
@klasses.reduce(false) { |memo, klass| memo ||= (other.class == klass) } | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment