简体   繁体   English

参数数量错误(0 代表 1)Ruby

[英]Wrong number of arguments (0 for 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

When I run this with当我运行它时

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

I get wrong number of arguments error?我得到错误数量的参数错误? I know that usually when it says wrong number it means that it's not exactly reading the argument that I put in. But I feel like I did put in an argument but I'm unsure of why it's not being read.我知道通常当它说错误的数字时,这意味着它没有完全阅读我输入的参数。但我觉得我确实输入了一个参数,但我不确定为什么没有阅读它。

In such cases, you should always paste the complete error message, and indicate which line in your code is affected.在这种情况下,您应该始终粘贴完整的错误消息,并指出代码中的哪一行受到影响。

Anyway, I can see that your wrote art = Ello::Hello.new (0 arguments), but the initialize method for this class expects 1 argument.无论如何,我可以看到你写的art = Ello::Hello.new (0 个参数),但是这个类的initialize方法需要 1 个参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM