0
我想需要的文件名如何从呼叫者获取文件名红宝石CGI
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
也许有可能使用呼叫者上课但我找不到。
在['Kernel.caller_locations'(https://ruby-doc.org/core-2.2.0/Thread/Backtrace/Location.html)看看。 – ndn
非常感谢。我知道了。 caller_locations(3).first.path – zari3
为您的问题写一个答案并接受它,以便将来的读者也可以轻松解决同样的问题。 – ndn