summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-11-27 09:23:38 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2000-11-27 09:23:38 +0000
commitf54418b71f57e00d4a50bd86bf7d18b8b5195287 (patch)
treed5bd57142a0d4736fdfd1f35dcd864ac40cfb045 /range.c
parent1f297b8bfc0fdacb8cfb19736cf224b2550281b3 (diff)
matz
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1053 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r--range.c29
1 files changed, 22 insertions, 7 deletions
diff --git a/range.c b/range.c
index 96f9fd6..ed835c2 100644
--- a/range.c
+++ b/range.c
@@ -13,10 +13,10 @@
#include "ruby.h"
VALUE rb_cRange;
-static ID id_cmp, id_beg, id_end;
+static ID id_cmp, id_beg, id_end, id_excl;
-#define EXCL(r) FL_TEST((r), FL_USER1)
-#define SET_EXCL(r) FL_SET((r), FL_USER1)
+#define EXCL(r) RTEST(rb_ivar_get((r), id_excl))
+#define SET_EXCL(r,v) rb_ivar_set((r), id_excl, (v)?Qtrue:Qfalse)
static VALUE
range_check(args)
@@ -46,10 +46,7 @@ range_init(obj, beg, end, exclude_end)
rb_eStandardError, rb_eNameError, 0);
}
- if (exclude_end) {
- SET_EXCL(obj);
- }
-
+ SET_EXCL(obj, exclude_end);
rb_ivar_set(obj, id_beg, beg);
rb_ivar_set(obj, id_end, end);
}
@@ -90,6 +87,22 @@ range_exclude_end_p(range)
}
static VALUE
+range_eq(range, obj)
+ VALUE range, obj;
+{
+ if (!rb_obj_is_kind_of(obj, rb_cRange)) return Qfalse;
+
+ if (!rb_equal(rb_ivar_get(range, id_beg), rb_ivar_get(obj, id_beg)))
+ return Qfalse;
+ if (!rb_equal(rb_ivar_get(range, id_end), rb_ivar_get(obj, id_end)))
+ return Qfalse;
+
+ if (EXCL(range) != EXCL(obj)) return Qfalse;
+
+ return Qtrue;
+}
+
+static VALUE
range_eqq(range, obj)
VALUE range, obj;
{
@@ -338,6 +351,7 @@ Init_Range()
rb_cRange = rb_define_class("Range", rb_cObject);
rb_include_module(rb_cRange, rb_mEnumerable);
rb_define_method(rb_cRange, "initialize", range_initialize, -1);
+ rb_define_method(rb_cRange, "==", range_eq, 1);
rb_define_method(rb_cRange, "===", range_eqq, 1);
rb_define_method(rb_cRange, "each", range_each, 0);
rb_define_method(rb_cRange, "first", range_first, 0);
@@ -355,4 +369,5 @@ Init_Range()
id_cmp = rb_intern("<=>");
id_beg = rb_intern("begin");
id_end = rb_intern("end");
+ id_excl = rb_intern("excl");
}