首页 > 解决方案 > 参数数量错误(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

我得到错误数量的参数错误?我知道通常当它说错误的数字时,这意味着它没有完全阅读我输入的论点。但我觉得我确实输入了一个论点,但我不确定为什么它没有被阅读。

标签: ruby

解决方案


在这种情况下,您应该始终粘贴完整的错误消息,并指出代码中的哪一行受到影响。

无论如何,我可以看到你写的art = Ello::Hello.new(0 个参数),但是initialize这个类的方法需要 1 个参数。


推荐阅读