1,使用迭代器和join的不同
- data=['1','2','3']
- s=''
- data.each{|x| s<<x<<' and '}
- puts s
- puts data.join(" and ")
line 4输出的是:1 and 2 and 3 and
line 5则是:1 and 2 and 3
可以使用each_with_index实现join
data.each_with_index{|x,i| ss<<x;ss<<' and ' if i<data.length-1}
2,<< pk +
使用前者向string中append时会比后者的性能有所提高,因为后者会创建新的string对象。
3,1)#{}中定义的变量或者类可以在#{}之外使用
puts "Here is #{
class Bar
def bar
" some text"
end
end
Bar.new.bar}"
bar=Bar.new
puts bar.bar
输出:Here is some text
some text
2)避免#{}的转义作用
foo="foo"
puts "\##{foo}"
puts '#{foo}'
puts '\#{foo}'
puts "#{foo}"
puts "\#"
3)使用END
name = "Mr. Lorum"
email = <<END
Dear #{name},
Unfortunately we cannot process your insurance claim at this
time. This is because we are a bakery, not an insurance company.
Signed,Nil, Null, and None
Bakers to Her Majesty the Singleton
END
puts email
biaoflying
相关推荐
abap tips abap tips abap tips abap tips abap tips
android TIPS小结android TIPS小结android TIPS小结android TIPS小结
中大ACM系统,一些使用建议 程序框架: 类型一:给定特定组数 类型二:多组数据,未知组数
swifter-tips.pdfswifter-tips.pdfswifter-tips.pdfswifter-tips.pdfswifter-tips.pdfswifter-tips.pdfswifter-tips.pdfswifter-tips.pdfswifter-tips.pdfswifter-tips.pdfswifter-tips.pdfswifter-tips.pdfswifter-...
jquery,tips,冒泡,jquery,tips,冒泡
jquery tips提示图片信息
* $(selector).tips({ //selector 为jquery选择器 * msg:'your messages!', //你的提示消息 必填 * side:1, //提示窗显示位置 1,2,3,4 分别代表 上右下左 默认为1(上) 可选 * color:'#FFF', //提示文字色 默认...
wxPython Grid Tips and Tricks
10 Tips to Help You Achieve Your Software Testing Documentation Goal 10 Tips to Help You Achieve Your Software Testing Documentation Goal
100 power tips for fpga designers
Quickly access 50 tips for software test engineers using automated methods. The tips point to practices that save time and increase the accuracy and reliability of automated test techniques. ...
【JS提示语tips】tips.class.demo
Microsoft visual studio tips pdf
Onevcat Swifter - Swift 开发者必备 Tips
一个非常好的tips
gate driver design tips
Android-Tips This is an awesome list of tips for android. If you are a beginner, this list will be the first choice for you when you have a difficult time. Welcome Star and Fork, your support is my ...
KTH-TIPS 纹理材质数据.zip
Swift 开发者必备 Tips, swift tips. 介绍 Swift 使用中那些隐藏的小技巧,帮助您迅速熟悉和掌握 Swift 编程语言 Swift 是 Apple 于 WWDC 2014 提出的一门全新的开发语言。这门语言从其他很多语言中继承和学习了不少...
Career Fair Tips From USC