class Object def not NotClass.new(self) end end class NotClass < BasicObject instance_methods.grep(/^[^_]/).each { |m| undef_method m } def initialize(object) @object = object end def method_missing(name, *args, &block) !@object.send(name, *args, &block) end end puts nil.not.nil? puts 1.not.eql?(2) puts [1, 3, 5, 7, 9].not.any? { |i| i % 2 == 0 } require "benchmark" Benchmark.bm do |x| x.report { 1.upto(1_000_000) { 1.not == 2 } } x.report { 1.upto(1_000_000) { 1 != 2 } } end # user system total real # 0.302335 0.001475 0.303810 ( 0.303833) # 0.035334 0.000051 0.035385 ( 0.035446)