directory - Get path of parent requiring file, Ruby -


Is it possible to get the location of the file, for which another file is required in Ruby?

I have a project where I used to create some processes and I would love to be able to code to make sure which file is the parent of the required file, it is good when debugging .

Example:

  # initial.rb: "./my_file.rb" is required "fork" / my_file2.rb "end  < / Pre> 

-

  # my_file.rb: puts "required from file: # {?????}"   

-

  # my_file2.rb: Required "./my_file.rb"   

I hope to do something like this:

 Required from file  # = & gt; /path/to/initial.rb # = & gt; Required from file: /path/to/my_file2.rb    

Based on the end I need need_relative and to < Red> | "\ t # {x}"} "% s requires% s "% [Caller.first.split (/: \ d + /, 2). First, arg] Old_require_related Arg end alias: old_require: def requirement (arg) # ~ collar.map {| x |" \ t # X} "}"% s requires% s "% [caller.first.split (/: \ d + /, 2). First, arg] old_require arg end

In a test test scenario with the following load sequence:

  test.rb + - test1.rb + - test1_a.rb + test2.rb   

Call

  is required './test1' is required './test2' '  

or

  Required_related 'test1' needs_r Results in elative 'test2' '  

:

  test.rb is required ./test1 C: /Temp/test1.rb test1_a test.rb Required is required ./test2   

You can also include the required line in the output.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -