Something went wrong. Try again.
A thing you shouldn't do, but can
Something went wrong. Try again.
662 B · 32 lines · Created 1y ago
Ruby
123456789101112131415161718192021222324252627282930313233class Object def not NotClass.new(self) endend
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) endend
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)