require 'fiddle'
class Object
def find_nearest spec
found = nil
[-1, 1].map { |dir|
Thread.new { |i = 0|
while !found && i += dir
obj = ObjectSpace._id2ref __id__ + i rescue next
break found = obj if spec === obj
end
}
}.each(&:join)
found
end
end
e = Enumerator.new { |y| y << 42 }
e.next
p e.find_nearest Fiber