From 3b7fa3e1b4d41468f97ae16bec421a013b4a3740 Mon Sep 17 00:00:00 2001 From: Wayne Conrad Date: Fri, 16 May 2014 04:57:42 -0700 Subject: [PATCH 1/1] * re.c (rb_reg_to_regexp): add to_regexp. --- ChangeLog | 4 ++++ re.c | 7 +++++++ test/ruby/test_regexp.rb | 5 +++++ 3 files changed, 16 insertions(+) diff --git a/ChangeLog b/ChangeLog index dfccc8f..52b344c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +Thu May 15 21:04:30 2014 Wayne Conrad + + * re.c (rb_reg_to_regexp): Regexp#to_regexp [Feature #9846] + Thu May 15 18:57:23 2014 Koichi Sasada * gc.c (garbage_collect_body): move gc_heap_prepare_minimum_pages() diff --git a/re.c b/re.c index 89910f6..f5729aa 100644 --- a/re.c +++ b/re.c @@ -3165,6 +3165,12 @@ rb_reg_options(VALUE re) } VALUE +rb_reg_to_regexp(VALUE re) +{ + return rb_convert_type(re, T_REGEXP, "Regexp", "to_regexp"); +} + +VALUE rb_check_regexp_type(VALUE re) { return rb_check_convert_type(re, T_REGEXP, "Regexp", "to_regexp"); @@ -3641,6 +3647,7 @@ Init_Regexp(void) rb_define_method(rb_cRegexp, "fixed_encoding?", rb_reg_fixed_encoding_p, 0); rb_define_method(rb_cRegexp, "names", rb_reg_names, 0); rb_define_method(rb_cRegexp, "named_captures", rb_reg_named_captures, 0); + rb_define_method(rb_cRegexp, "to_regexp", rb_reg_to_regexp, 0); /* see Regexp.options and Regexp.new */ rb_define_const(rb_cRegexp, "IGNORECASE", INT2FIX(ONIG_OPTION_IGNORECASE)); diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index de8ecdb..ed85318 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -1028,6 +1028,11 @@ class TestRegexp < Test::Unit::TestCase RUBY end + def test_to_regexp + re = // + assert_same(re, re.to_regexp) + end + # This assertion is for porting x2() tests in testpy.py of Onigmo. def assert_match_at(re, str, positions, msg = nil) re = Regexp.new(re) unless re.is_a?(Regexp) -- 1.9.1