0

I have an array in my model but I don't know how to access it from some defs in this model

private 

topics =
[
'en','Sports','sports',
'en','Sports,Soccer,Football','soccer,football',
]

def self.load   
    topics.each_slice(3).map do |lang,tags,searchterms|
        load_data(lang,tags,searchterms) 
    end 
end

But when I try from to execute from console it shows an error

NameError: undefined local variable or method `topics' for Class:

I don't want to declare the array inside def because I need other methods from model can access to this array

Any idea? thanks

1 Answer 1

1

Because you've defined topics as local variable but trying to get it as class variable.

Just change it to @@topics both in the definition and in the method load, then it should work.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.