Skip to content

Instantly share code, notes, and snippets.

@robertdfrench
Created April 1, 2025 16:07
Show Gist options
  • Save robertdfrench/36e072e4c14bd493f5afd5cf9f9b0341 to your computer and use it in GitHub Desktop.
Save robertdfrench/36e072e4c14bd493f5afd5cf9f9b0341 to your computer and use it in GitHub Desktop.
April Fools' 2025: Randomly lie about .nil? to make a ruby program undebuggable
#!/usr/bin/ruby
# A Mean Ruby trick for April Fools
#
# This is why code review is important.
module NilTracer
def self.included(base)
base.class_eval do
alias_method :original_nil?, :nil?
def nil?
if rand(3) == 0
return (not original_nil?)
end
original_nil?
end
end
end
end
Object.include(NilTracer)
NilClass.include(NilTracer)
puts "5 is never nil"
x = 5
10.times { || puts x.nil? }
puts "nil is always nil"
x = nil
10.times { || puts x.nil? }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment