R
Rick DeNatale
I'm writing something which is partially written in ruby, but uses an
extension which adds methods to some of the classes in the ruby part.
Right now I've got a directory which contains both the ruby code and
the so containing the extensions
$ls
mycode.rb mycode_prims.so
in mycode.rb I've got something like:
class Mycode
def foo
end
end
# link in the primitives, mycode_prims includes various calls to
# rb_define_method to add methods to the Mycode class.
require 'mycode_prims'
Now this works if the directory containing both parts is the current
directory, but not otherwise. Actually I guess it would work as long
as the directory was on the load path, but I'm concerned about the
possibility of loading the wrong mycode_prims.so.
Is there a way to get the directory containing the current source
file? __FILE__ only gives the file name, but not the path.
What is the right way to do this? I'd like to know how to approach
this either with the code packaged as a gem or as 'source'.
extension which adds methods to some of the classes in the ruby part.
Right now I've got a directory which contains both the ruby code and
the so containing the extensions
$ls
mycode.rb mycode_prims.so
in mycode.rb I've got something like:
class Mycode
def foo
end
end
# link in the primitives, mycode_prims includes various calls to
# rb_define_method to add methods to the Mycode class.
require 'mycode_prims'
Now this works if the directory containing both parts is the current
directory, but not otherwise. Actually I guess it would work as long
as the directory was on the load path, but I'm concerned about the
possibility of loading the wrong mycode_prims.so.
Is there a way to get the directory containing the current source
file? __FILE__ only gives the file name, but not the path.
What is the right way to do this? I'd like to know how to approach
this either with the code packaged as a gem or as 'source'.