Created
October 3, 2012 10:42
-
-
Save sobrinho/3826332 to your computer and use it in GitHub Desktop.
Proof of concept for `(a | b).empty?` on ruby
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
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? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
cool, can you really use | as the declaration of a method?