Is Ruby Matrix set_element private?

When called set_elementin an instance of the Matrix class, I get the following error:

NoMethodError: private methodset_elementcalled for Matrix[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]:Matrix

But set_elementindicated in the public instance methods in the documentation

Matrix # set_element

In addition, set_element is an alias for [] = (i, j, v) and with this method I get the following error

ArgumentError: wrong number of arguments (3 for 2)

It makes no sense, any help is appreciated.

Ruby 1.9.2 p180

+5
source share
2 answers

The documentation is incorrect. If you look at the file matrix.rbwith 1.9.1, you will see the following:

def []=(i, j, v)
  @rows[i][j] = v
end
alias set_element []=
alias set_component []=
private :[]=, :set_element, :set_component

Thus, there are three methods, but they are explicitly defined as private.

, , , . , , , -, ; , rdoc, .

, Matrix , Fixnum Number.

+1

setter , , ( ):

class SetableMatrix < Matrix
  public :"[]=", :set_element, :set_component
end
+6

All Articles