Undefined local variable or method brands for class

I have written this ruby class matrixgorup.rb · GitHub and I am getting “undefined local variable or method brands for class”

If I change def brands to def self.brands it works, why is this?

Thanks

That is due to different scopes: you are calling brands from within a class method, hence it searches for a class method i.e. self.class and not an instance one.

If you consider that, it makes a lot of sense: you haven’t created an instance of the class to talk too :slight_smile:

Now I feel silly, makes perfect sense! Thanks pedro!

No worries, that is a fairly regular trip-up :slight_smile: