From fac245828b9e354c9eeb93a029f1643031c3c62d Mon Sep 17 00:00:00 2001 From: marcandre Date: Thu, 1 Apr 2010 18:02:27 +0000 Subject: * 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 --- lib/matrix.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'lib/matrix.rb') diff --git a/lib/matrix.rb b/lib/matrix.rb index 25245fd15c..6227c435bf 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -386,6 +386,14 @@ class Matrix # TESTING -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- #++ + # + # 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. # @@ -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}" -- cgit v1.2.3