2017-07-27 83 views
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 

也许有可能使用呼叫者上课但我找不到。

+0

在['Kernel.caller_locations'(https://ruby-doc.org/core-2.2.0/Thread/Backtrace/Location.html)看看。 – ndn

+0

非常感谢。我知道了。 caller_locations(3).first.path – zari3

+0

为您的问题写一个答案并接受它,以便将来的读者也可以轻松解决同样的问题。 – ndn

回答

0

解决了。

filename = caller_locations(3).first.path 

该数字应该改变取决于深度。

感谢NDN