summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-03-12 07:22:55 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>1998-03-12 07:22:55 +0000
commit89843627b8ec3fe619d7b270500b08f1e014ca17 (patch)
treec90e86350ce6c43258468c3e31754a19f0be3413 /range.c
parent1acc981a539813e6ec2a5c50f3d91f946a4da1a6 (diff)
range check
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@118 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r--range.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/range.c b/range.c
index 06fef09..a3f8865 100644
--- a/range.c
+++ b/range.c
@@ -18,19 +18,32 @@ extern VALUE cNumeric;
static ID upto;
static VALUE
+range_check(args)
+ VALUE *args;
+{
+ VALUE v = rb_funcall(args[0], rb_intern("<="), 1, args[1]);
+
+ if (!RTEST(v)) {
+ Fail(""); /* no ascending values */
+ }
+ return Qnil;
+}
+
+static VALUE
+range_failed()
+{
+ ArgError("bad value for range");
+}
+
+static VALUE
range_s_new(klass, first, last)
VALUE klass, first, last;
{
VALUE obj;
+ VALUE args[2];
- if (!(FIXNUM_P(first) && FIXNUM_P(last))
- && (TYPE(first) != TYPE(last)
- || CLASS_OF(first) != CLASS_OF(last)
- || !rb_respond_to(first, upto))
- && !(obj_is_kind_of(first, cNumeric)
- && obj_is_kind_of(last, cNumeric))) {
- ArgError("bad value for range");
- }
+ args[0] = first; args[1] = last;
+ rb_rescue(range_check, args, range_failed, 0);
obj = obj_alloc(klass);