[前][次][番号順一覧][スレッド一覧]

ruby-changes:38523

From: marcandre <ko1@a...>
Date: Fri, 22 May 2015 22:37:01 +0900 (JST)
Subject: [ruby-changes:38523] marcandRe: r50604 (trunk): * lib/prime.rb: Remove obsolete Prime.new

marcandre	2015-05-22 22:36:39 +0900 (Fri, 22 May 2015)

  New Revision: 50604

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=50604

  Log:
    * lib/prime.rb: Remove obsolete Prime.new
      patch by Ajay Kumar. [Fixes GH-891]

  Modified files:
    trunk/ChangeLog
    trunk/lib/prime.rb
    trunk/test/test_prime.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 50603)
+++ ChangeLog	(revision 50604)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri May 22 22:36:14 2015  Marc-Andre Lafortune  <ruby-core@m...>
+
+	* lib/prime.rb: Remove obsolete Prime.new
+	  patch by Ajay Kumar. [Fixes GH-891]
+
 Fri May 22 21:13:12 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* include/ruby/intern.h (rb_sym_count): move `rb_sym_all_symbols`
Index: lib/prime.rb
===================================================================
--- lib/prime.rb	(revision 50603)
+++ lib/prime.rb	(revision 50604)
@@ -57,9 +57,6 @@ end https://github.com/ruby/ruby/blob/trunk/lib/prime.rb#L57
 #
 # == 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 https://github.com/ruby/ruby/blob/trunk/lib/prime.rb#L87
 
 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 https://github.com/ruby/ruby/blob/trunk/lib/prime.rb#L124
   #   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 https://github.com/ruby/ruby/blob/trunk/lib/prime.rb#L444
       @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
Index: test/test_prime.rb
===================================================================
--- test/test_prime.rb	(revision 50603)
+++ test/test_prime.rb	(revision 50604)
@@ -1,6 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/test/test_prime.rb#L1
 require 'test/unit'
 require 'prime'
-require 'stringio'
 require 'timeout'
 
 class TestPrime < Test::Unit::TestCase
@@ -54,23 +53,18 @@ class TestPrime < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/test_prime.rb#L53
     assert enum.respond_to?(:rewind)
   end
 
-  def test_new
-    orig_stderr, orig_verbose = $stderr, $VERBOSE
-
-    $stderr = buf = StringIO.new('', 'w')
-    $VERBOSE = false
-
-    enum = Prime.new
-    assert_match("obsolete", buf.string)
-
+  def test_instance_without_block
+    enum = Prime.instance.each
     assert enum.respond_to?(:each)
     assert enum.kind_of?(Enumerable)
+    assert enum.respond_to?(:with_index)
+    assert enum.respond_to?(:next)
     assert enum.respond_to?(:succ)
+    assert enum.respond_to?(:rewind)
+  end
 
-    assert Prime === enum
-  ensure
-    $stderr = orig_stderr
-    $VERBOSE = orig_verbose
+  def test_new
+    exception = assert_raises(NoMethodError) { Prime.new }
   end
 
   def test_enumerator_succ

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]