Project

General

Profile

Actions

Feature #2265

closed

Matrix#empty? [patch]

Added by marcandre (Marc-Andre Lafortune) about 15 years ago. Updated over 13 years ago.

Status:
Closed
Target version:
[ruby-core:26284]

Description

=begin
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}"
    =end
Actions

Also available in: Atom PDF

Like0
Like0Like0