Skip to content

Instantly share code, notes, and snippets.

@bchase
Created August 28, 2014 09:57
Show Gist options
  • Save bchase/a81f5dabd45b31ba2f2b to your computer and use it in GitHub Desktop.
Save bchase/a81f5dabd45b31ba2f2b to your computer and use it in GitHub Desktop.
we do what we must because we can
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