Skip to content

Instantly share code, notes, and snippets.

@sobrinho
Created October 3, 2012 10:42
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 sobrinho/3826332 to your computer and use it in GitHub Desktop.
Save sobrinho/3826332 to your computer and use it in GitHub Desktop.
Proof of concept for `(a | b).empty?` on ruby
class Or < BasicObject
def initialize(a, b)
@a = a
@b = b
end
def method_missing(method_name, *arguments, &block)
@a.send(method_name, *arguments, &block) || @b.send(method_name, *arguments, &block)
end
end
class Object
def |(other)
Or.new(self, other)
end
end
username = 'sobrinho'
password = '123456'
(username | password).empty?
@thiagofm
Copy link

thiagofm commented Oct 3, 2012

cool, can you really use | as the declaration of a method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment