aboutsummaryrefslogtreecommitdiffstats
path: root/lib/matrix.rb
diff options
context:
space:
mode:
authormarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-01 18:02:27 +0000
committermarcandre <marcandre@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-04-01 18:02:27 +0000
commitfac245828b9e354c9eeb93a029f1643031c3c62d (patch)
tree23377f9cd8739da0096c24ded2cc671017ac9564 /lib/matrix.rb
parent39aad8fa8364d12b5888c8ae24f3b47b7d06f99c (diff)
downloadruby-fac245828b9e354c9eeb93a029f1643031c3c62d.tar.gz
* lib/matrix.rb: New method #empty? [ruby-core:26284]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@27156 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/matrix.rb')
-rw-r--r--lib/matrix.rb12
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/matrix.rb b/lib/matrix.rb
index 25245fd15c..6227c435bf 100644
--- a/lib/matrix.rb
+++ b/lib/matrix.rb
@@ -387,6 +387,14 @@ class Matrix
#++
#
+ # Returns +true+ if this is an empty matrix, i.e. if the number of rows
+ # or the number of columns is 0.
+ #
+ def empty?
+ column_size == 0 || row_size == 0
+ end
+
+ #
# Returns +true+ if this is a regular matrix.
#
def regular?
@@ -910,7 +918,7 @@ class Matrix
# Overrides Object#to_s
#
def to_s
- if row_size == 0 || column_size == 0
+ if empty?
"Matrix.empty(#{row_size}, #{column_size})"
else
"Matrix[" + @rows.collect{|row|
@@ -923,7 +931,7 @@ class Matrix
# Overrides Object#inspect
#
def inspect
- if row_size == 0 || column_size == 0
+ if empty?
"Matrix.empty(#{row_size}, #{column_size})"
else
"Matrix#{@rows.inspect}"