summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-03 01:02:15 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-05-03 01:02:15 (GMT)
commitb0616346f8098d0f2063c48ee61c09eb2ddc851e (patch)
treeadcbfe02df54f0815c1b296d174ba9ebf1b743df /range.c
parent06cb32001ff6825d733ed00029f3f1f68d672faf (diff)
range.c: covered for linear objects
* range.c (linear_object_p, range_include): test if covered for linear objects. [ruby-core:69052] [Bug #11113] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@50421 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r--range.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/range.c b/range.c
index d44f322..54c7d88 100644
--- a/range.c
+++ b/range.c
@@ -331,6 +331,21 @@ discrete_object_p(VALUE obj)
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)
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")) ||