From: Marc-Andre Lafortune Date: 2009-10-25T07:33:09+09:00 Subject: [ruby-core:26284] [Feature #2265] Matrix#empty? [patch] Feature #2265: Matrix#empty? [patch] http://redmine.ruby-lang.org/issues/show/2265 Author: Marc-Andre Lafortune Status: Open, Priority: Normal Assigned to: Keiju Ishitsuka, Category: lib Now that the Matrix library handles well empty matrices, how about a new instance method #empty? diff --git a/lib/matrix.rb b/lib/matrix.rb index b577ef3..45ef25e 100644 --- a/lib/matrix.rb +++ b/lib/matrix.rb @@ -386,6 +386,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? @@ -924,7 +932,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| @@ -939,7 +947,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}" ---------------------------------------- http://redmine.ruby-lang.org