From: zn@... Date: 2014-08-26T00:38:09+00:00 Subject: [ruby-core:64557] [ruby-trunk - Bug #10167] Prime#include?(mod) hangs up Issue #10167 has been updated by Kazuhiro NISHIYAMA. workaround: ~~~ enumerables = [] module_include_p = Module.method(:include?).unbind ObjectSpace.each_object(Class) do |klass| if module_include_p.bind(klass).call(Enumerable) enumerables.push klass end end ~~~ ---------------------------------------- Bug #10167: Prime#include?(mod) hangs up https://bugs.ruby-lang.org/issues/10167#change-48484 * Author: Kenichi Saita * Status: Open * Priority: Normal * Assignee: * Category: lib * Target version: current: 2.2.0 * ruby -v: ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux] * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN ---------------------------------------- We expect `Prime` class implements `Module#include?(mod)`. But `Prime#include?(mod)` hangs up, because it is overwritten by `Enumerable#include?(obj)` and tries to search `mod` linearly from infinite sequence of prime numbers. **Reproducible script:** ~~~ $ ruby -e 'require "prime"; puts Prime.include?(Enumerable)' ~~~ * Expected: returns `true` * Actual: hangs up I found this bug by the following code (hangs up if prime is required) ~~~ enumerables = [] ObjectSpace.each_object(Class){|klass| if klass.include?(Enumerable) then enumerables.push klass end } ~~~ -- https://bugs.ruby-lang.org/