码迷,mamicode.com
首页 > 其他好文 > 详细

LRTHW笔记六

时间:2014-09-01 17:32:43      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   os   ar   div   log   sp   on   

源码ex6-2.rb

types_of_people = 10
x = "There are #{types_of_people} types of people."    
binary = "binary"
do_not = "don‘t"
y = "Those who know ‘#{binary}‘ and those who #{do_not}."
z = Those who know "#{binary}" and those who #{do_not}.
puts x
puts y

puts "I said: #{x}"
puts "I also said: ‘#{y}‘."
puts "I also said: ‘#{z}‘."

结果是:

[ufindme@ufindme rubywork]$ ruby  ex6-2.rb 
There are 10 types of people.
Those who know binary and those who dont.
I said: There are 10 types of people.
I also said: Those who know binary and those who dont..
I also said: Those who know "#{binary}" and those who #{do_not}..

这里注意一点:

  双引号里面的单引号是原样输出,而单引号里面的双引号也是原样输出。

  双引号里面的变量的输出时,变量用实际的值代替后输出显示。

  单引号是不管引号里面的是什么,都源码输出,也没有替代。

 

LRTHW笔记六

标签:style   blog   color   os   ar   div   log   sp   on   

原文地址:http://www.cnblogs.com/ufindme/p/3949530.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!