summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--range.c4
-rw-r--r--test/ruby/test_range.rb4
3 files changed, 14 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 4451ca8adbb..3f2bdfed3a9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -72,6 +72,14 @@ Tue Aug 4 12:40:45 2009 NARUSE, Yui <naruse@ruby-lang.org>
* enc/encdb.c (ENC_SET_BASE): fix typo.
patch by ujihisa [ruby-dev:39004]
+Tue Aug 4 11:57:39 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
+
+ * range.c (range_eql, range_eq): fixed equality to work for
+ subclasses of Range. a patch from Marc-Andre Lafortune.
+ [ruby-core:22190]
+
+ * test/ruby/test_range.rb: add assertions for above.
+
Tue Aug 4 09:41:11 2009 NARUSE, Yui <naruse@ruby-lang.org>
* enc/big5.c (EncLen_Big5): back to original Big5 table.
diff --git a/range.c b/range.c
index e013a8a13f4..6431fc9ceeb 100644
--- a/range.c
+++ b/range.c
@@ -125,7 +125,7 @@ range_eq(VALUE range, VALUE obj)
{
if (range == obj)
return Qtrue;
- if (!rb_obj_is_instance_of(obj, rb_obj_class(range)))
+ if (!rb_obj_is_kind_of(obj, rb_cRange))
return Qfalse;
if (!rb_equal(RANGE_BEG(range), RANGE_BEG(obj)))
@@ -187,7 +187,7 @@ range_eql(VALUE range, VALUE obj)
{
if (range == obj)
return Qtrue;
- if (!rb_obj_is_instance_of(obj, rb_obj_class(range)))
+ if (!rb_obj_is_kind_of(obj, rb_cRange))
return Qfalse;
if (!rb_eql(RANGE_BEG(range), RANGE_BEG(obj)))
diff --git a/test/ruby/test_range.rb b/test/ruby/test_range.rb
index b4c078915df..9dfd29012ab 100644
--- a/test/ruby/test_range.rb
+++ b/test/ruby/test_range.rb
@@ -89,6 +89,8 @@ class TestRange < Test::Unit::TestCase
assert(r != (1..2))
assert(r != (0..2))
assert(r != (0...1))
+ subclass = Class.new(Range)
+ assert(r == subclass.new(0,1))
end
def test_eql
@@ -99,6 +101,8 @@ class TestRange < Test::Unit::TestCase
assert(!r.eql?(1..2))
assert(!r.eql?(0..2))
assert(!r.eql?(0...1))
+ subclass = Class.new(Range)
+ assert(r.eql?(subclass.new(0,1)))
end
def test_hash