记录器Rails中的奇怪行为

时间:2014-01-27 18:41:14

标签: ruby-on-rails ruby logging

我试图在我的rails 4应用程序中添加一些日志记录语句并遇到这种奇怪的行为。

我将名为blah的实例变量定义为

@blah = 'test'

现在,如果我这样做

logger.debug 'this string is #{@blah}'

输出

I, [2014-01-27T13:36:06.047288 #8864]  INFO -- : this string is #{@blah}

但如果我这样做

 logger.info "this string is #{@blah}" #note the double quotes

输出

I, [2014-01-27T13:36:00.236707 #8864]  INFO -- : this string is test

看起来像logger中的字符串插值只有在字符串用双引号而不是单引号括起时才有效。这是正常的吗?如果是这样,任何人都知道为什么?

1 个答案:

答案 0 :(得分:0)

> rp@foo:~$ irb
> 2.1.0 :001 > @foo = 'bar'  => "bar" 
> 2.1.0 :002 > '#{@foo}'  => "\#{@foo}" 
> 2.1.0 :003 >
> 2.1.0 :003 > "#{@foo}"
> => "bar"

这应该是它应该如何。

相关问题