问题描述
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个参数。