Skip to content

Instantly share code, notes, and snippets.

@stretchkennedy
Created August 25, 2014 07:00
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/69a4a508ba02cb275a8f to your computer and use it in GitHub Desktop.
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.
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