ruby - 参数数量错误(0 代表 1)Ruby
问题描述
def self.grab
article = self.article_names
links = self.article_links
body = self.article_body
articles = {}
articles[:title] = article
articles[:url] = links
articles[:body] = body
art = Ello::Hello.new
art(articles)
end
当我运行这个
class Ello::Hello
attr_accessor :url, :article, :body,
@@all = []
def initialize(hash)
@article = hash["title"]
@body = hash["body"]
@url = hash["url"]
@@all << self
end
def self.all
@@all
end
end
我得到错误数量的参数错误?我知道通常当它说错误的数字时,这意味着它没有完全阅读我输入的论点。但我觉得我确实输入了一个论点,但我不确定为什么它没有被阅读。
解决方案
在这种情况下,您应该始终粘贴完整的错误消息,并指出代码中的哪一行受到影响。
无论如何,我可以看到你写的art = Ello::Hello.new
(0 个参数),但是initialize
这个类的方法需要 1 个参数。
推荐阅读
- javascript - Asp.net 项目 - Javascript 按钮可点击但不执行该功能
- reactjs - 在从 `useEffect` 调用的`useCallback` 中设置和使用状态时的无限循环
- swift - 如何正确挑选出单元格附件视图
- python - Redis后台任务完成后如何在Flask上重定向?
- java - 声明一个布尔变量然后分配一个表达式
- nuxt.js - Nuxt 和 Contentful:重复的路由
- java - 在不同函数中调用时变量无法正常工作
- angular - Angular Material Autocomplete 以显示来自 RestApi 的员工姓名
- sonarqube - Azure App Service Linux 容器上的 SonarQube dockerfile:错误容器没有响应端口:8080 上的 HTTP ping,站点启动失败
- sapui5 - sapui5 在 SAPUI5 中上传文件并在 odata 服务实体集中发送该文件