Project

General

Profile

This project is closed and read-only.

Actions

Bug #1518

closed

Matrix#[] Raises NoMethodError for Invalid Index

Bug #1518: Matrix#[] Raises NoMethodError for Invalid Index

Added by runpaint (Run Paint Run Run) over 17 years ago. Updated over 15 years ago.


Description

=begin

m = Matrix[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11]]
>> m[2,8]
=> nil
>> m[8,2]
NoMethodError: undefined method []' for nil:NilClass from /usr/lib/ruby/1.9.0/matrix.rb:264:in []'
from (irb):13
from /usr/bin/irb1.9:12:in `

'

The #[] accessor for Matrix raises a particularly disconcerting NoMethodError when its passed an index which is out of bounds for the second argument. To be consistent with itself, it should return nil when either index is invalid.
=end


Related issues 1 (0 open1 closed)

Related to Ruby - Bug #1532: Improved matrix.rb [patch]Closedkeiju (Keiju Ishitsuka)Actions
Actions

Also available in: PDF Atom