diff options
| author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-15 12:09:30 +0000 |
|---|---|---|
| committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-09-15 12:09:30 +0000 |
| commit | b4248a27101ea40c35f057e2b11110892879edf0 (patch) | |
| tree | 8101f907eab3c501038f104b06aaba254b9b7854 /lib | |
| parent | d58d4bbf0fec627dcf428e967b170326db017ad5 (diff) | |
* lib/matrix.rb (Matrix#eql?): fixed [ruby-dev:36298].
Reported by an anonymous user.
* lib/matrix.rb (Vector#eql?): ditto.
* (Matrix#compare_by_row_vectors): takes comparison
strategy as an optional parameter.
* (Vector#compare_by): ditto.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@19361 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/matrix.rb | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/matrix.rb b/lib/matrix.rb index b1ee76f34b..90b9587efe 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -402,17 +402,21 @@ class Matrix other.compare_by_row_vectors(@rows) end - alias eql? == + def eql?(other) + return false unless Matrix === other + + other.compare_by_row_vectors(@rows, :eql?) + end # # Not really intended for general consumption. # - def compare_by_row_vectors(rows) + def compare_by_row_vectors(rows, comparison = :==) return false unless @rows.size == rows.size 0.upto(@rows.size - 1) do |i| - return false unless @rows[i] == rows[i] + return false unless @rows[i].send(comparison, rows[i]) end true end @@ -1087,13 +1091,17 @@ class Vector other.compare_by(@elements) end - alias eql? == + def eql?(other) + return false unless Vector === other + + other.compare_by(@elements, :eql?) + end # # For internal use. # - def compare_by(elements) - @elements == elements + def compare_by(elements, comparison = :==) + @elements.send(comparison, elements) end # |
