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

ruby-changes:38340

From: nobu <ko1@a...>
Date: Sun, 3 May 2015 10:02:22 +0900 (JST)
Subject: [ruby-changes:38340] nobu:r50421 (trunk): range.c: covered for linear objects

nobu	2015-05-03 10:02:15 +0900 (Sun, 03 May 2015)

  New Revision: 50421

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

  Log:
    range.c: covered for linear objects
    
    * range.c (linear_object_p, range_include): test if covered for
      linear objects.  [ruby-core:69052] [Bug #11113]

  Modified files:
    trunk/ChangeLog
    trunk/range.c
    trunk/test/ruby/test_range.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 50420)
+++ ChangeLog	(revision 50421)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun May  3 10:02:12 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* range.c (linear_object_p, range_include): test if covered for
+	  linear objects.  [ruby-core:69052] [Bug #11113]
+
 Fri May  1 13:30:24 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* dln.c (dln_load): check if a different libruby is loaded by the
Index: range.c
===================================================================
--- range.c	(revision 50420)
+++ range.c	(revision 50421)
@@ -331,6 +331,21 @@ discrete_object_p(VALUE obj) https://github.com/ruby/ruby/blob/trunk/range.c#L331
     return rb_respond_to(obj, id_succ);
 }
 
+static int
+linear_object_p(VALUE obj)
+{
+    if (FIXNUM_P(obj) || FLONUM_P(obj)) return TRUE;
+    if (SPECIAL_CONST_P(obj)) return FALSE;
+    switch (BUILTIN_TYPE(obj)) {
+      case T_FLOAT:
+      case T_BIGNUM:
+	return TRUE;
+    }
+    if (rb_obj_is_kind_of(obj, rb_cNumeric)) return TRUE;
+    if (rb_obj_is_kind_of(obj, rb_cTime)) return TRUE;
+    return FALSE;
+}
+
 static VALUE
 range_step_size(VALUE range, VALUE args, VALUE eobj)
 {
@@ -1156,8 +1171,7 @@ range_include(VALUE range, VALUE val) https://github.com/ruby/ruby/blob/trunk/range.c#L1171
     VALUE beg = RANGE_BEG(range);
     VALUE end = RANGE_END(range);
     int nv = FIXNUM_P(beg) || FIXNUM_P(end) ||
-	     rb_obj_is_kind_of(beg, rb_cNumeric) ||
-	     rb_obj_is_kind_of(end, rb_cNumeric);
+	     linear_object_p(beg) || linear_object_p(end);
 
     if (nv ||
 	!NIL_P(rb_check_to_integer(beg, "to_int")) ||
Index: test/ruby/test_range.rb
===================================================================
--- test/ruby/test_range.rb	(revision 50420)
+++ test/ruby/test_range.rb	(revision 50421)
@@ -283,6 +283,14 @@ class TestRange < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_range.rb#L283
     assert_not_operator(0..10, :===, 11)
   end
 
+  def test_eqq_time
+    bug11113 = '[ruby-core:69052] [Bug #11113]'
+    t = Time.now
+    assert_nothing_raised(TypeError, bug11113) {
+      assert_operator(t..(t+10), :===, t+5)
+    }
+  end
+
   def test_include
     assert_include("a".."z", "c")
     assert_not_include("a".."z", "5")

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

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