Skip to content

Instantly share code, notes, and snippets.

Created September 1, 2015 11:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/bc66831b12a71ce877eb to your computer and use it in GitHub Desktop.
Save anonymous/bc66831b12a71ce877eb to your computer and use it in GitHub Desktop.
Gem's initialization 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
2. Include the initialization in the only method of the Gem. We can
safely assume that the 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?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment