Skip to content

Instantly share code, notes, and snippets.

@havenwood
Last active May 26, 2022 21:07
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save havenwood/bdc8b23f8ec374ec3e0c9a330ee30938 to your computer and use it in GitHub Desktop.
Save havenwood/bdc8b23f8ec374ec3e0c9a330ee30938 to your computer and use it in GitHub Desktop.
Does your Range exclude end? Make it a surprise!
require 'fiddle'
class RangeWithIndeterminateExclusion < Range
def initialize min, max
pointer = Fiddle::Pointer.new Fiddle.dlwrap self
Thread.new do
loop do
sleep rand
pointer[Fiddle::SIZEOF_LONG * 4] ^= true.object_id
end
end
super
end
end
range = RangeWithIndeterminateExclusion.new 1, 10
#=> 1..10
range
#=> 1...10
range
#=> 1..10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment