| Navigation:First_Community->Software->Script(Perl,Python,Ruby,etc.) | Goto:New Topic•Setting•Search | |
MegaEntry - Social networking and discussion site!
puts 6/2 print 6/1 puts 'hello world ' puts '我们都是 ' '中国人 '
3 6hello world 我们都是中国人
a=1 b=1.0 c=1.0 d=1.0 e=c puts(a==b)#值相等 puts(a.eql?(b)) #值相等,类型相等 puts(c.equal?(d))#值相等,内存地址相等 puts(c.equal?(e))
CopyRight owned by the original author.--(www.MegaEntry.com)
ruby 代码true false false true
puts( "abd " <=> "acd ") puts((0..5) === 10) puts((0..5) === 3.2)
MegaEntry - Social networking and discussion site!
运行结果:-1 false true
x=3 case x when 1..2 print "x= ",x, ",在1..2中 " when 4..9,0 print "x= ",x, ",在4..9,0中 " else print "x= ",x, ",其它可能 " end 输出结果: x=3,其它可能
CopyRight owned by the original author.--(www.MegaEntry.com)
A:ruby里的字符串连接用的是逗号(java里用的是加号),如: puts( "aaa ", "bbb ") print( "aaa ", "bbb ") 分别输出为aaa换行bbb,aaabbb B:ruby里好像没有++,所以a++是错误的,只能a=a+1MegaEntry - Social networking and discussion site!
ruby 代码a=1 while( a < 10 ) print(a, " ") a=a+1 end b=1 until( b >= 10 ) print(b, " ") b=b+1 end 输出结果为: 1 2 3 4 5 6 7 8 9 1 2 3 4 5 6 7 8 9
MegaEntry - Social networking and discussion site!
end ruby 代码3.times{print "hi "} 1.upto(9){|i| print i if i<7>#|i|可以看成是一个临时的引用变量,供后面使用 9.downto(1){|i| print i if i<7> (1..9).each{|i| print i if i<7> 0.step(11,3){|i| print i} 运行结果: hihihi123456654321123456036