Forum: Ruby-core Prime#include?(mod) hangs up

5b783edb8af956f941da7da7d1b2bf74?d=identicon&s=25 unknown (Guest)
on 2014-08-29 19:11
(Received via mailing list)
Issue #10167 has been updated by Kenichi Saita.

File prime-include.diff added

It's difficult to delete `Prime.inlude?` method because this method is
included by `include Enumerable`.

So, I overrided `Prime.include?` and `Prime.instance.include?`. Please
review my patch.

Bug #10167: Prime#include?(mod) hangs up

* 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 = []
  if klass.include?(Enumerable) then
    enumerables.push klass

prime-include.diff (1.21 KB)
This topic is locked and can not be replied to.