summaryrefslogtreecommitdiff
path: root/range.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-11-08 09:21:59 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-11-08 09:21:59 +0000
commitcf4451e8c27936dcd71b5eac7105ff52e02f1e95 (patch)
tree14d1818ca2fd8543ef14ccdcb47c55827bdf9815 /range.c
parentdc98adf839d0d68c4c18647a1db2fb3dc9be8cc4 (diff)
* file.c (path_check_1): forgot to initialize 'p'.
* mkconfig.rb: use String#dump to generate Ruby string literal. * range.c (range_eql): should override 'eql?' * array.c (rb_ary_hash): should override 'hash' too. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1817 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'range.c')
-rw-r--r--range.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/range.c b/range.c
index 9f6581f..abfebf5 100644
--- a/range.c
+++ b/range.c
@@ -201,6 +201,38 @@ range_eqq(range, obj)
}
static VALUE
+range_eql(range, obj)
+ VALUE range, obj;
+{
+ if (range == obj) return Qtrue;
+ if (!rb_obj_is_kind_of(obj, rb_cRange)) return Qfalse;
+
+ if (!rb_eql(rb_ivar_get(range, id_beg), rb_ivar_get(obj, id_beg)))
+ return Qfalse;
+ if (!rb_eql(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_hash(range, obj)
+ VALUE range, obj;
+{
+ long hash = EXCL(range);
+ VALUE v;
+
+ v = rb_hash(rb_ivar_get(range, id_beg));
+ hash ^= v << 1;
+ v = rb_hash(rb_ivar_get(range, id_end));
+ hash ^= v << 9;
+
+ return INT2FIX(hash);
+}
+
+static VALUE
range_each(range)
VALUE range;
{
@@ -524,6 +556,8 @@ Init_Range()
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, "eql?", range_eql, 1);
+ rb_define_method(rb_cRange, "hash", range_hash, 0);
rb_define_method(rb_cRange, "each", range_each, 0);
rb_define_method(rb_cRange, "step", range_step, -1);
rb_define_method(rb_cRange, "first", range_first, 0);