mirror of
https://github.com/ruby/ruby.git
synced 2025-08-23 13:04:13 +02:00
merge revision(s) 50421: [Backport #11113]
* 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/branches/ruby_2_1@50581 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
137514a399
commit
7a03d4637c
4 changed files with 30 additions and 3 deletions
18
range.c
18
range.c
|
@ -329,6 +329,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)
|
||||
{
|
||||
|
@ -1148,8 +1163,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")) ||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue