rainslg
rainslg

Reputation: 455

missing `@` on instance variable

I have a Ruby class with an initialize method:

def initialize(params)
  @foo = private_method(params || {})
end

Later in the same class, I see the following:

def new_method_for(user)
  foo.each { |f| other_method(f) }
end

Why is the @ missing from in front of foo in other_method? When I put a binding.pry in before foo.each..., both foo and @foo are defined.

Upvotes: 0

Views: 91

Answers (1)

Cyzanfar
Cyzanfar

Reputation: 7146

Check for the class that contains the new_method_for(user) method, you should see an attr_reader, attr_writer or both represented by attr_accessor

So it should look like this:

class SomeClass
 attr_accessor :foo

end

Upvotes: 1

Related Questions