ruby-changes:58589
From: Nobuyoshi <ko1@a...>
Date: Wed, 6 Nov 2019 09:04:38 +0900 (JST)
Subject: [ruby-changes:58589] aa94245a09 (master): Undefine MatchData.allocate [Feature #16294]
https://git.ruby-lang.org/ruby.git/commit/?id=aa94245a09 From aa94245a09887f95bc0cd353b3462108d76d13ed Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Wed, 6 Nov 2019 08:54:32 +0900 Subject: Undefine MatchData.allocate [Feature #16294] diff --git a/re.c b/re.c index 34880a8..4b9d662 100644 --- a/re.c +++ b/re.c @@ -4110,6 +4110,7 @@ Init_Regexp(void) https://github.com/ruby/ruby/blob/trunk/re.c#L4110 rb_cMatch = rb_define_class("MatchData", rb_cObject); rb_define_alloc_func(rb_cMatch, match_alloc); rb_undef_method(CLASS_OF(rb_cMatch), "new"); + rb_undef_method(CLASS_OF(rb_cMatch), "allocate"); rb_define_method(rb_cMatch, "initialize_copy", match_init_copy, 1); rb_define_method(rb_cMatch, "regexp", match_regexp, 0); diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 05099d3..a1d49c5 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -1002,6 +1002,8 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L1002 assert_raise(TypeError) { Regexp.allocate.names } assert_raise(TypeError) { Regexp.allocate.named_captures } + assert_not_respond_to(MatchData, :allocate) +=begin assert_raise(TypeError) { MatchData.allocate.hash } assert_raise(TypeError) { MatchData.allocate.regexp } assert_raise(TypeError) { MatchData.allocate.names } @@ -1024,6 +1026,7 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L1026 assert_raise(TypeError) { $` } assert_raise(TypeError) { $' } assert_raise(TypeError) { $+ } +=end end def test_unicode @@ -1093,7 +1096,9 @@ class TestRegexp < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_regexp.rb#L1096 assert_equal(a, b, '[ruby-core:24748]') h = {a => 42} assert_equal(42, h[b], '[ruby-core:24748]') +=begin assert_match(/#<TestRegexp::MatchData_\u{3042}:/, MatchData_A.allocate.inspect) +=end h = /^(?<@time>\d+): (?<body>.*)/.match("123456: hoge fuga") assert_equal("123456", h["@time"]) -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/