0
新手问题,我尝试在ruby应用程序中尝试调试错误, 你可以看到它here。Ruby:空字符串和空字符串有什么不同?
代码:
def self.default_url_options
options = {:protocol => Setting.protocol}
if Setting.host_name.to_s =~ /\A(https?\:\/\/)?(.+?)(\:(\d+))?(\/.+)?\z/i
host, port, prefix = $2, $4, $5
options.merge!({
:host => host, :port => port, :script_name => prefix
})
else
options[:host] = Setting.host_name
end
options
end
如果我host, port, prefix = $2, $4, $5
后添加日志记录:
host, port, prefix = $2, $4, $5
Rails.logger.error "!!!!!!! '#{host}', '#{port}', '#{prefix}'"
我: !!!!!!! “hostname.net”,“”,“”
所以prefix
是空的,但如果设置:script_name
明确地''
改变程序的行为,我得到预期的结果,在 换句话说:
:script_name => ''
和空$5
给出不同的结果。
- 空
$5
和空字符串有什么区别? - 从ruby程序员的角度来看这个问题的正确解决方法是什么?
空的'$ 5'是指'nil'? – Aleksey