From: Jean-denis Vauguet on
s/along the file.rb/along the main.rb/
--
Posted via http://www.ruby-forum.com/.

From: Jean-denis Vauguet on
Ok so here's what I eventually did:

require 'pathname' # I love it :)
module MyLib
def self.extended base #:nodoc:
# the receiver is the extended module or class
@receiver = base

# paths of the receiver file and receiver stuff
@base_path = Pathname.new(File.expand_path($0)).dirname
@stuff_path = @base_path + "mylib_stuff"

# ... do whatever with base and the paths
end

# ...
end

I don't know if this practice of relying on $0 is solid, though.
Any hint?
--
Posted via http://www.ruby-forum.com/.

From: Brian Candler on
Jean-denis Vauguet wrote:
> I don't know if this practice of relying on $0 is solid, though.

It's very risky:
* on many platforms it's truncated
* the script which the user started running isn't necessarily the file
which is requiring your code

I suggest you look at Kernel#caller instead.

Unfortunately it just gives you strings which you have to parse
yourself, and you'll probably need to grep out all the rubygems-related
paths.

For an example, look in the sinatra gem (lib/sinatra/base.rb,
specifically methods caller_locations and caller_files). Sinatra uses
this to locate the application source code, for reading inline
templates.

--
Posted via http://www.ruby-forum.com/.

From: Jean-denis Vauguet on
Brian Candler wrote:
> I suggest you look at Kernel#caller instead.
>
> Unfortunately it just gives you strings which you have to parse
> yourself, and you'll probably need to grep out all the rubygems-related
> paths.
>
> For an example, look in the sinatra gem (lib/sinatra/base.rb,
> specifically methods caller_locations and caller_files). Sinatra uses
> this to locate the application source code, for reading inline
> templates.

Thank you so much :)
--
Posted via http://www.ruby-forum.com/.