Gem coding advise

I’m creating a Gem but I’m struggling to decide it’s initialization.

I have 2 options:

  1. 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

  1. 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?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs