summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-12-07 08:41:59 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2005-12-07 08:41:59 +0000
commitda32ce1a67677bd0f5df8fa31e0ab05c26c7d401 (patch)
tree88fbca16ba3c3b802990d969a13a57ec67bb3ab0 /range.c
parente122cca1791b38e089776bfeb39f0bd1d07afdae (diff)
* 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.c31
1 files changed, 20 insertions, 11 deletions
diff --git a/range.c b/range.c
index 12ea69daaa..d18b4efe01 100644
--- a/range.c
+++ b/range.c
@@ -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);
}