I’m creating a Gem but I’m struggling to decide it’s initialization.
I have 2 options:
- Require the user to manually initialize the Gem:
Module MyGem
def self.init
@my_var = db_resource
end
def self.do_action
puts @my_var
end
end
- Include the initialization in the only method of the Gem. We can
safely assume that any app will call the Gem’s method in O(n).
Module MyGem
def self.do_action
@my_var ||= db_resource
puts @my_var
end
end
So WDYT?