Reputation: 1955
I would like to define the variable @@importers when my module loads.
module Importers
@@importers_dir = File.dirname(__FILE__) + '/services/'
@@importers = self.load_and_instantiate()
def self.load_and_instantiate()
#mycode here
end
end
But it does not work :
undefined method 'load_and_instantiate' for Importers:Module (NoMethodError)
How should I handle this ?
Thanks !
Upvotes: 0
Views: 40
Reputation: 107142
At the moment you call load_and_instantiate
it is indeed not defined because you define it later in the code.
Just change the order and call the method after you defined the method:
def self.load_and_instantiate
# mycode here
end
@@importers = self.load_and_instantiate
Please note that using class variables is uncommon in Ruby.
Upvotes: 2