LRTHW笔记六

博客围绕Ruby语言展开,介绍了源码ex6 - 2.rb相关内容。着重讲解了引号使用规则,双引号里单引号原样输出,单引号里双引号也原样输出;双引号里变量输出时用实际值替代,单引号则原样输出无替代。

源码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 don't.
I said: There are 10 types of people.
I also said: 'Those who know 'binary' and those who don't.'.
I also said: 'Those who know "#{binary}" and those who #{do_not}.'.

这里注意一点:

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

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

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

 

转载于:https://www.cnblogs.com/ufindme/p/3949530.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值