Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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