Skip to content

Instantly share code, notes, and snippets.

@Epigene
Created February 18, 2017 12:39
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 Epigene/a57af7ff1806825e779da5744e9e31b1 to your computer and use it in GitHub Desktop.
Save Epigene/a57af7ff1806825e779da5744e9e31b1 to your computer and use it in GitHub Desktop.
Shows how to define a .root method for a gem module
# 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