Bug #10167
closedPrime#include?(mod) hangs up
Description
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:
- Expected: returns
true - Actual: hangs up
I found this bug by the following code (hangs up if prime is required)
Files
Updated by znz (Kazuhiro NISHIYAMA) about 12 years ago
Updated by nobu (Nobuyoshi Nakada) about 12 years ago
- Description updated (diff)
Even Prime.include?(4) hangs up too.
This method seems useless.
Updated by nitoyon (Kenichi Saita) about 12 years ago
- File prime-include.diff 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.
Updated by nitoyon (Kenichi Saita) about 12 years ago
Review my patch, please!
Updated by marcandre (Marc-Andre Lafortune) almost 12 years ago
- Assignee set to yugui (Yuki Sonoda)
Instead of aliasing include? to prime?, I'd recommend instead to restore it:
Prime.define_singleton_method(:include?, Module.instance_method(:include?))
Prime.include?(Enumerable) # => true
Probably won't be super useful, but still beats an infinite loop :-)
Assigning to yugui, although I have not seen any activity from her in over a year on the mailing list?
Updated by naruse (Yui NARUSE) over 8 years ago
- Target version deleted (
2.2.0)
Updated by jeremyevans0 (Jeremy Evans) about 7 years ago
I've added a pull request for this at https://github.com/ruby/prime/pull/6.
Updated by jeremyevans0 (Jeremy Evans) over 6 years ago
- Status changed from Open to Closed