Last active
May 26, 2022 21:07
-
-
Save havenwood/bdc8b23f8ec374ec3e0c9a330ee30938 to your computer and use it in GitHub Desktop.
Does your Range exclude end? Make it a surprise!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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