如何从调用者获取ruby cgi的文件名

时间:2021-10-19 15:59:44

I want to get file name that require

我想获得所需的文件名

index.rb

puts "<html><head></head><body>"

require 'test.rb'

puts "</body></html>"

test.rb

# here I want to get 'index.rb' to go to the case select statement to change output html

puts <<"EOS"
<p> HTML output bla bla bla </p>
EOS

maybe it's possible using caller class but i couldn't find out.

也许它可以使用调用者类但我无法找到。

1 个解决方案

#1


0  

solved.

filename = caller_locations(3).first.path

the number should be changed depends on the depth.

数量应根据深度而改变。

thanks ndn

#1


0  

solved.

filename = caller_locations(3).first.path

the number should be changed depends on the depth.

数量应根据深度而改变。

thanks ndn