Michelle
Michelle

Reputation: 11

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.

Upvotes: 0

Views: 165

Answers (1)

user1934428
user1934428

Reputation: 22356

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.

Upvotes: 1

Related Questions