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

ruby-changes:54108

From: nobu <ko1@a...>
Date: Tue, 11 Dec 2018 13:35:17 +0900 (JST)
Subject: [ruby-changes:54108] nobu:r66329 (trunk): date_core.c: moved some methods to DateTime

nobu	2018-12-11 13:35:13 +0900 (Tue, 11 Dec 2018)

  New Revision: 66329

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

  Log:
    date_core.c: moved some methods to DateTime
    
    * ext/date/date_core.c (Init_date_core): moved methods which make
      sense only for DateTime to that class, instead of defining
      private methods in Date and making them public in DateTime.

  Modified files:
    trunk/ext/date/date_core.c
    trunk/test/date/test_switch_hitter.rb
Index: ext/date/date_core.c
===================================================================
--- ext/date/date_core.c	(revision 66328)
+++ ext/date/date_core.c	(revision 66329)
@@ -9377,16 +9377,6 @@ Init_date_core(void) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L9377
     de_define_method(cDate, "nth_kday?", d_lite_nth_kday_p, 2);
 #endif
 
-    rb_define_private_method(cDate, "hour", d_lite_hour, 0);
-    rb_define_private_method(cDate, "min", d_lite_min, 0);
-    rb_define_private_method(cDate, "minute", d_lite_min, 0);
-    rb_define_private_method(cDate, "sec", d_lite_sec, 0);
-    rb_define_private_method(cDate, "second", d_lite_sec, 0);
-    rb_define_private_method(cDate, "sec_fraction", d_lite_sec_fraction, 0);
-    rb_define_private_method(cDate, "second_fraction", d_lite_sec_fraction, 0);
-    rb_define_private_method(cDate, "offset", d_lite_offset, 0);
-    rb_define_private_method(cDate, "zone", d_lite_zone, 0);
-
     rb_define_method(cDate, "julian?", d_lite_julian_p, 0);
     rb_define_method(cDate, "gregorian?", d_lite_gregorian_p, 0);
     rb_define_method(cDate, "leap?", d_lite_leap_p, 0);
@@ -9398,8 +9388,6 @@ Init_date_core(void) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L9388
     rb_define_method(cDate, "julian", d_lite_julian, 0);
     rb_define_method(cDate, "gregorian", d_lite_gregorian, 0);
 
-    rb_define_private_method(cDate, "new_offset", d_lite_new_offset, -1);
-
     rb_define_method(cDate, "+", d_lite_plus, 1);
     rb_define_method(cDate, "-", d_lite_minus, 1);
 
@@ -9631,19 +9619,16 @@ Init_date_core(void) https://github.com/ruby/ruby/blob/trunk/ext/date/date_core.c#L9619
     rb_define_singleton_method(cDateTime, "jisx0301",
 			       datetime_s_jisx0301, -1);
 
-#define f_public(m,s) rb_funcall(m, rb_intern("public"), 1,\
-				 ID2SYM(rb_intern(s)))
-
-    f_public(cDateTime, "hour");
-    f_public(cDateTime, "min");
-    f_public(cDateTime, "minute");
-    f_public(cDateTime, "sec");
-    f_public(cDateTime, "second");
-    f_public(cDateTime, "sec_fraction");
-    f_public(cDateTime, "second_fraction");
-    f_public(cDateTime, "offset");
-    f_public(cDateTime, "zone");
-    f_public(cDateTime, "new_offset");
+    rb_define_method(cDateTime, "hour", d_lite_hour, 0);
+    rb_define_method(cDateTime, "min", d_lite_min, 0);
+    rb_define_method(cDateTime, "minute", d_lite_min, 0);
+    rb_define_method(cDateTime, "sec", d_lite_sec, 0);
+    rb_define_method(cDateTime, "second", d_lite_sec, 0);
+    rb_define_method(cDateTime, "sec_fraction", d_lite_sec_fraction, 0);
+    rb_define_method(cDateTime, "second_fraction", d_lite_sec_fraction, 0);
+    rb_define_method(cDateTime, "offset", d_lite_offset, 0);
+    rb_define_method(cDateTime, "zone", d_lite_zone, 0);
+    rb_define_method(cDateTime, "new_offset", d_lite_new_offset, -1);
 
     rb_define_method(cDateTime, "to_s", dt_lite_to_s, 0);
 
Index: test/date/test_switch_hitter.rb
===================================================================
--- test/date/test_switch_hitter.rb	(revision 66328)
+++ test/date/test_switch_hitter.rb	(revision 66329)
@@ -187,18 +187,18 @@ class TestSH < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/date/test_switch_hitter.rb#L187
     d = Date.jd(Rational(2451944))
     assert_equal(2451944, d.jd)
     d = Date.jd(2451944.5)
-    assert_equal([2451944, 12], [d.jd, d.send('hour')])
+    assert_equal(2451944, d.jd)
     d = Date.jd(Rational('2451944.5'))
-    assert_equal([2451944, 12], [d.jd, d.send('hour')])
+    assert_equal(2451944, d.jd)
 
     d = Date.civil(2001, 2, 3.0)
     assert_equal([2001, 2, 3], [d.year, d.mon, d.mday])
     d = Date.civil(2001, 2, Rational(3))
     assert_equal([2001, 2, 3], [d.year, d.mon, d.mday])
     d = Date.civil(2001, 2, 3.5)
-    assert_equal([2001, 2, 3, 12], [d.year, d.mon, d.mday, d.send('hour')])
+    assert_equal([2001, 2, 3], [d.year, d.mon, d.mday])
     d = Date.civil(2001, 2, Rational('3.5'))
-    assert_equal([2001, 2, 3, 12], [d.year, d.mon, d.mday, d.send('hour')])
+    assert_equal([2001, 2, 3], [d.year, d.mon, d.mday])
 
     d = Date.ordinal(2001, 2.0)
     assert_equal([2001, 2], [d.year, d.yday])
@@ -266,10 +266,8 @@ class TestSH < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/date/test_switch_hitter.rb#L266
   end
 
   def test_zone
-    d = Date.new(2001, 2, 3)
-    assert_equal(Encoding::US_ASCII, d.send(:zone).encoding)
     d = DateTime.new(2001, 2, 3)
-    assert_equal(Encoding::US_ASCII, d.send(:zone).encoding)
+    assert_equal(Encoding::US_ASCII, d.zone.encoding)
   end
 
   def test_to_s
@@ -534,7 +532,6 @@ class TestSH < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/date/test_switch_hitter.rb#L532
     s = "\x04\x03u:\x01\x04Date\x01\v\x04\x03[\x01\x02i\x03\xE8i%T"
     d = Marshal.load(s)
     assert_equal(Rational(4903887,2), d.ajd)
-    assert_equal(0, d.send(:offset))
     assert_equal(Date::GREGORIAN, d.start)
   end
 
@@ -542,7 +539,6 @@ class TestSH < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/date/test_switch_hitter.rb#L539
     s = "\x04\x06u:\tDate\x0F\x04\x06[\ai\x03\xE8i%T"
     d = Marshal.load(s)
     assert_equal(Rational(4903887,2), d.ajd)
-    assert_equal(0, d.send(:offset))
     assert_equal(Date::GREGORIAN, d.start)
   end
 
@@ -550,7 +546,6 @@ class TestSH < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/date/test_switch_hitter.rb#L546
     s = "\x04\bu:\tDateP\x04\b[\bo:\rRational\a:\x0F@numeratori\x03\xCF\xD3J:\x11@denominatori\ai\x00o:\x13Date::Infinity\x06:\a@di\xFA"
     d = Marshal.load(s)
     assert_equal(Rational(4903887,2), d.ajd)
-    assert_equal(0, d.send(:offset))
     assert_equal(Date::GREGORIAN, d.start)
 
     s = "\x04\bu:\rDateTime`\x04\b[\bo:\rRational\a:\x0F@numeratorl+\b\xC9\xB0\x81\xBD\x02\x00:\x11@denominatori\x02\xC0\x12o;\x00\a;\x06i\b;\ai\ro:\x13Date::Infinity\x06:\a@di\xFA"
@@ -564,7 +559,6 @@ class TestSH < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/date/test_switch_hitter.rb#L559
     s = "\x04\bU:\tDate[\bU:\rRational[\ai\x03\xCF\xD3Ji\ai\x00o:\x13Date::Infinity\x06:\a@di\xFA"
     d = Marshal.load(s)
     assert_equal(Rational(4903887,2), d.ajd)
-    assert_equal(Rational(0,24), d.send(:offset))
     assert_equal(Date::GREGORIAN, d.start)
 
     s = "\x04\bU:\rDateTime[\bU:\rRational[\al+\b\xC9\xB0\x81\xBD\x02\x00i\x02\xC0\x12U;\x06[\ai\bi\ro:\x13Date::Infinity\x06:\a@di\xFA"

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

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