Ruby Matrix set_element 私有(private)?

标签 ruby matrix ruby-1.9.2 access-specifier

在 Matrix 类的实例上调用 set_element 时出现以下错误

NoMethodError: private method ‘set_element’ called for Matrix[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]:Matrix

但是 set_element 列在文档中的公共(public)实例方法下

Matrix#set_element

此外,set_element 是 []=(i, j, v) 的别名并使用此方法我得到以下错误

ArgumentError: wrong number of arguments (3 for 2)

没有任何意义,感谢任何帮助。

ruby 1.9.2 p180

最佳答案

您可以简单地公开 setter 函数,可能在您自己的类中(或在 Matrix 本身):

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

关于Ruby Matrix set_element 私有(private)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6463668/

相关文章:

android - 重新缩放 ImageView 的位图时图像质量下降

sql - 如何编写SQL来在Oracle中显示我的案例中的数据?

ruby-on-rails-3 - Neo4j ActiveRecord 支持使用 Ruby 作为解释器

ruby-on-rails - 开始使用 MiniTest 和 Rails

ruby - Telnet 在 Ruby 中不工作

ruby - 如何设置 ruby​​ murmur 哈希的种子值

ruby - 为什么 rubocop 或 ruby​​ 风格指南不喜欢使用 get_ 或 set_?

c++ - OpenCV:归一化太慢或者我做错了?

ruby - 如何在 Mac OSX 10.7.3 LION 上使用 RVM 安装 Ruby 1.9.2?

c - 将 ruby​​ 数组值传递到 C 数组