0
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.

3
  • 1
    Use Ello::Hello.new(articles) instead, the parameters must be passed right when you initialize a new object. Commented Aug 31, 2020 at 5:34
  • The error message tells you what line the error occurs on. Commented Aug 31, 2020 at 8:14
  • Seeing a class variable here is usually a sign things have gone awry. Consider using a different approach, like where self.all is defined as @all ||= [ ] and then you can do self.class.all << self in the instance if you need this. Remember retaining every object can prevent the garbage collector from doing its job. Commented Sep 1, 2020 at 0:05

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.