diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-12-07 08:41:59 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-12-07 08:41:59 +0000 |
commit | da32ce1a67677bd0f5df8fa31e0ab05c26c7d401 (patch) | |
tree | 88fbca16ba3c3b802990d969a13a57ec67bb3ab0 /range.c | |
parent | e122cca1791b38e089776bfeb39f0bd1d07afdae (diff) | |
download | ruby-da32ce1a67677bd0f5df8fa31e0ab05c26c7d401.tar.gz |
* sprintf.c (rb_f_sprintf): [ruby-dev:27967]
* range.c (range_include): use discrete membership for non Numeric
values, for example, String.
* numeric.c (num_scalar_p): new method. [ruby-dev:27936]
* lib/complex.rb (Complex#scalar?): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9654 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r-- | range.c | 31 |
1 files changed, 20 insertions, 11 deletions
@@ -618,19 +618,28 @@ range_inspect(VALUE range) static VALUE range_include(VALUE range, VALUE val) { - VALUE beg, end; - - beg = rb_ivar_get(range, id_beg); - end = rb_ivar_get(range, id_end); - if (r_le(beg, val)) { - if (EXCL(range)) { - if (r_lt(val, end)) return Qtrue; - } - else { - if (r_le(val, end)) return Qtrue; + VALUE beg = rb_ivar_get(range, id_beg); + VALUE end = rb_ivar_get(range, id_end); + VALUE tmp; + int nv = FIXNUM_P(beg) || FIXNUM_P(end) || + rb_obj_is_kind_of(beg, rb_cNumeric) || + rb_obj_is_kind_of(end, rb_cNumeric); + + if (nv) { + numeric_range: + if (r_le(beg, val)) { + if (EXCL(range)) { + if (r_lt(val, end)) return Qtrue; + } + else { + if (r_le(val, end)) return Qtrue; + } } } - return Qfalse; + if (!NIL_P(rb_check_to_integer(beg, "to_int")) || + !NIL_P(rb_check_to_integer(end, "to_int"))) + goto numeric_range; + return rb_call_super(1, &val); } |