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

ruby-changes:52040

From: mrkn <ko1@a...>
Date: Thu, 9 Aug 2018 22:18:15 +0900 (JST)
Subject: [ruby-changes:52040] mrkn:r64256 (trunk): enumerator.c: undef new and allocate of ArithmeticSequence

mrkn	2018-08-09 22:18:08 +0900 (Thu, 09 Aug 2018)

  New Revision: 64256

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

  Log:
    enumerator.c: undef new and allocate of ArithmeticSequence
    
    Undefine new and allocate methods of Enumerator::ArithmeticSequence.
    
    [ruby-core:82816] [Feature #13904]

  Modified files:
    trunk/enumerator.c
    trunk/test/ruby/test_arithmetic_sequence.rb
Index: test/ruby/test_arithmetic_sequence.rb
===================================================================
--- test/ruby/test_arithmetic_sequence.rb	(revision 64255)
+++ test/ruby/test_arithmetic_sequence.rb	(revision 64256)
@@ -2,6 +2,14 @@ https://github.com/ruby/ruby/blob/trunk/test/ruby/test_arithmetic_sequence.rb#L2
 require 'test/unit'
 
 class TestArithmeticSequence < Test::Unit::TestCase
+  def test_new
+    assert_raise(NoMethodError) { Enumerator::ArithmeticSequence.new }
+  end
+
+  def test_allocate
+    assert_raise(TypeError) { Enumerator::ArithmeticSequence.allocate }
+  end
+
   def test_begin
     assert_equal(1, 1.step.begin)
     assert_equal(1, 1.step(10).begin)
Index: enumerator.c
===================================================================
--- enumerator.c	(revision 64255)
+++ enumerator.c	(revision 64256)
@@ -2844,6 +2844,8 @@ InitVM_Enumerator(void) https://github.com/ruby/ruby/blob/trunk/enumerator.c#L2844
 
     /* ArithmeticSequence */
     rb_cArithSeq = rb_define_class_under(rb_cEnumerator, "ArithmeticSequence", rb_cEnumerator);
+    rb_undef_alloc_func(rb_cArithSeq);
+    rb_undef_method(CLASS_OF(rb_cArithSeq), "new");
     rb_define_method(rb_cArithSeq, "begin", arith_seq_begin, 0);
     rb_define_method(rb_cArithSeq, "end", arith_seq_end, 0);
     rb_define_method(rb_cArithSeq, "exclude_end?", arith_seq_exclude_end, 0);

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

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