Aus*_*son 2 ruby matrix access-specifier
我制作了一个Matrix类,我想在代码的各个部分使用它.
class Matrix
def initialize(x, y, v=0)
@matrix = Array.new
(0..y).each do |j|
@matrix[j] = Array.new
(0..x).each do |i|
@matrix[j][i] = v
end
end
end
end
Run Code Online (Sandbox Code Playgroud)
当此代码与使用它的代码包含在同一个类中时,一切运行正常.
当我将此代码移动lib/matrix.rb并要求它时,我收到以下错误:
./phylograph:30:in `block in run': private method `new' called for Matrix:Class (NoMethodError)
Run Code Online (Sandbox Code Playgroud)