summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-22 13:36:39 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-22 13:36:39 +0000
commitd2487ed47587ec1cd1b456068e0af3ea0b39596d (patch)
treefd4f38aa449c0e0d945227a9db45931495233f0d /lib
parent3a08b7e2047235a4687944f1102d199f0ade48b3 (diff)
* lib/prime.rb: Remove obsolete Prime.new
patch by Ajay Kumar. [Fixes GH-891] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50604 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/prime.rb42
1 files changed, 1 insertions, 41 deletions
diff --git a/lib/prime.rb b/lib/prime.rb
index b2b55f1f2e..87bb284cea 100644
--- a/lib/prime.rb
+++ b/lib/prime.rb
@@ -57,9 +57,6 @@ end
#
# == Retrieving the instance
#
-# +Prime+.new is obsolete. Now +Prime+ has the default instance and you can
-# access it as +Prime+.instance.
-#
# For convenience, each instance method of +Prime+.instance can be accessed
# as a class method of +Prime+.
#
@@ -90,20 +87,11 @@ end
class Prime
include Enumerable
- @the_instance = Prime.new
-
- # obsolete. Use +Prime+::+instance+ or class methods of +Prime+.
- def initialize
- @generator = EratosthenesGenerator.new
- extend OldCompatibility
- warn "Prime::new is obsolete. use Prime::instance or class methods of Prime."
- end
+ include Singleton
class << self
extend Forwardable
include Enumerable
- # Returns the default instance of Prime.
- def instance; @the_instance end
def method_added(method) # :nodoc:
(class<< self;self;end).def_delegator :instance, method
@@ -136,14 +124,6 @@ class Prime
# Upper bound of prime numbers. The iterator stops after it
# yields all prime numbers p <= +ubound+.
#
- # == Note
- #
- # +Prime+.+new+ returns an object extended by +Prime+::+OldCompatibility+
- # in order to be compatible with Ruby 1.8, and +Prime+#each is overwritten
- # by +Prime+::+OldCompatibility+#+each+.
- #
- # +Prime+.+new+ is now obsolete. Use +Prime+.+instance+.+each+ or simply
- # +Prime+.+each+.
def each(ubound = nil, generator = EratosthenesGenerator.new, &block)
generator.upper_bound = ubound
generator.each(&block)
@@ -464,24 +444,4 @@ class Prime
@max_checked = segment_max
end
end
-
- # Provides a +Prime+ object with compatibility to Ruby 1.8 when instantiated via +Prime+.+new+.
- module OldCompatibility
- # Returns the next prime number and forwards internal pointer.
- def succ
- @generator.succ
- end
- alias next succ
-
- # Overwrites Prime#each.
- #
- # Iterates the given block over all prime numbers. Note that enumeration
- # starts from the current position of internal pointer, not rewound.
- def each
- return @generator.dup unless block_given?
- loop do
- yield succ
- end
- end
- end
end