孤独的猫

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

类似于C,一般用'\'作为转义字符

如'escape using "\\"'  将显示  escape using "\"

   'That\'s right'  显示 That's right

 

#{expr}序列把任何Ruby代码的值放入字符串中

"Seconds/day: #{24*60*60}" 得到  Seconds/day: 86400

"#{'Ho!   '*3'}Merry Christmas!" 得到  "Ho! Ho! Ho! Merry Christmas!" 

"This is line #$."  得到  This is line 3

 

进行插入替换的可以是一条或多条语句,如:

irb(main):007:0> puts "now is #{def the(a)
irb(main):008:0"     'the '+a
irb(main):009:0"    end
irb(main):010:0"     the('time')
irb(main):011:0"   }for all good..."
now is the timefor all good...
=> nil
irb(main):012:0>

posted on 2012-03-24 21:03  孤独的猫  阅读(143)  评论(0编辑  收藏  举报