Created
August 28, 2014 09:57
-
-
Save bchase/a81f5dabd45b31ba2f2b to your computer and use it in GitHub Desktop.
we do what we must because we can
This file contains 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 NotAble | |
def not | |
boolean_bizzaro_world | |
end | |
private | |
def boolean_methods | |
methods.select { |m| m.to_s.end_with? '?' } | |
end | |
def boolean_bizzaro_world | |
this = self | |
Object.new.tap do |obj| | |
boolean_methods.each do |method| | |
obj.define_singleton_method method, | |
-> (*args) { ! this.send method, *args } | |
end | |
end | |
end | |
end | |
String.include NotAble | |
''.empty? # => true | |
''.not.empty? # => false | |
''.kind_of? String # => true | |
''.not.kind_of? String # => false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment