Created
February 18, 2017 12:39
-
-
Save Epigene/a57af7ff1806825e779da5744e9e31b1 to your computer and use it in GitHub Desktop.
Shows how to define a .root method for a gem module
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
# in example_gem/lib/example_gem.rb | |
module ExampleGem | |
# ExampleGem.root | |
def self.root | |
current_file_name = __FILE__ | |
path_to_current_file = File.expand_path(current_file_name) | |
# get out of example_gem.rb file and then out of /lib to get to root | |
root_path = Pathname.new(path_to_current_file) + "../.." | |
# instead of `+ "../.."`, parent.parent also works | |
return root_path | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment