I’m actually writing my own RubyGem.
How do I get the path to the RubyGem, i.e. for requiring?
require "./mygeminternally.rb"
# => the path (actually "./") must be the path to the internals of the gem while it is being compiled
Is it just Dir.getwd? I need a method that brings me the path to the gem so I can use internal templates. Be aware that templates or configuration files have to be accessed while the gem is compiled, is this so easily possible like picking the right path?
Yours,
Joern
In a gem you should always use paths relative to your
libdir and never try to evaluate absolute paths because this can cause problems in some edge cases.When I say
libI actually mean one of the directories added torequire_pathsin the.gemspecfile, but in almost all cases this is set to just['lib'].This is all described in detail in the RubyGems Guide (as mentioned by @an4rco in his comment — give him an upvote).