-
-
Save anonymous/bc66831b12a71ce877eb to your computer and use it in GitHub Desktop.
Gem's initialization advise
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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