未定义的方法“构建”对于矩阵:类

发布于 2025-01-04 09:29:13 字数 863 浏览 3 评论 0原文

我在 Rails 应用程序中扩展了 Matrix 类,添加了两个新方法,如下所述:

两个扩展类 - 一个有效,另一个无效

上述方法现在可以正常工作。另外,一些现有方法可以正常工作,例如

Matrix.column_vector([4,5,6])
Matrix.columns([[25, 93], [-1, 66]])

Matrix.build(2, 4) {|row, col| col - row }
Matrix.build(3) { rand }

不起作用并给出错误

undefined method `build' for Matrix:Class    

这些方法都在此页面中定义:

http://www.ruby-doc.org/stdlib-1.9.3/libdoc/matrix/rdoc/Matrix.html#method-c-build

可能导致构建方法不起作用的原因,其他 Matrix 方法何时起作用?我错过了额外的图书馆或课程吗?

编辑1:我意识到这是因为当构建方法在 1.9.3 中定义时我有 ruby​​ 1.8.7

I have extended the Matrix class in my rails app to add two new methods as described here:

Two extended classes - one works and the other doesn't

The above methods now work fine. Also some of the existing methods work fine such as

Matrix.column_vector([4,5,6])
Matrix.columns([[25, 93], [-1, 66]])

but

Matrix.build(2, 4) {|row, col| col - row }
Matrix.build(3) { rand }

do not work and give the error

undefined method `build' for Matrix:Class    

The methods are all defined in this page here:

http://www.ruby-doc.org/stdlib-1.9.3/libdoc/matrix/rdoc/Matrix.html#method-c-build

What could be causing the build method to not work, when other Matrix methods do work? Am I missing an extra library or class?

EDIT 1: I realised it is because I have ruby 1.8.7 when the build method is defined in 1.9.3

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半衾梦 2025-01-11 09:29:13

我意识到这是因为我有 ruby​​ 1.8.7,而构建方法是在 1.9.3 中定义的

I realised it is because I have ruby 1.8.7 when the build method is defined in 1.9.3

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文