|
| 1 | +# Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. This |
| 2 | +# code is released under a tri EPL/GPL/LGPL license. You can use it, |
| 3 | +# redistribute it and/or modify it under the terms of the: |
| 4 | +# |
| 5 | +# Eclipse Public License version 2.0, or |
| 6 | +# GNU General Public License version 2, or |
| 7 | +# GNU Lesser General Public License version 2.1. |
| 8 | + |
| 9 | +example "Thread.detect_recursion(Object.new) { }", false |
| 10 | +example "Thread.detect_recursion([]) { }", false |
| 11 | +example "Thread.detect_recursion({}) { }", false |
| 12 | + |
| 13 | +example "y = nil; Thread.detect_recursion(Object.new) { y = Thread.detect_recursion(Object.new) { } }; y", false |
| 14 | +example "x = Object.new; y = nil; Thread.detect_recursion(x) { y = Thread.detect_recursion(x) { } }; y", true |
| 15 | + |
| 16 | +def detect_recursion_recursive(method, object) |
| 17 | + Thread.detect_recursion(object) do |
| 18 | + object.send(method) do |child| |
| 19 | + return detect_recursion_recursive(method, child) |
| 20 | + end |
| 21 | + end |
| 22 | +end |
| 23 | + |
| 24 | +example "detect_recursion_recursive(:each, [])", false |
| 25 | +example "detect_recursion_recursive(:each_value, {})", false |
| 26 | +example "a = []; a << a; detect_recursion_recursive(:each, a)", true |
| 27 | +example "a = {}; a[:a] = a; detect_recursion_recursive(:each_value, a)", true |
0 commit comments