Ruby的标准类型:
A.数字
class Test
3 . times { print " X " }
1 . upto( 5 ) { | i | print i , " " }
99 . downto( 95 ) { | i | print i , " " }
50 . step( 80 , 5 ) { | i | print i , " " }
a = " 23 "
b = " 34 "
puts " "
puts a + b
puts Integer(a) + Integer(b)
end
3 . times { print " X " }
1 . upto( 5 ) { | i | print i , " " }
99 . downto( 95 ) { | i | print i , " " }
50 . step( 80 , 5 ) { | i | print i , " " }
a = " 23 "
b = " 34 "
puts " "
puts a + b
puts Integer(a) + Integer(b)
end
输出:
X X X 1 2 3 4 5 99 98 97 96 95 50 55 60 65 70 75 80
2334
57
B.字符串
class Test
puts " That's right "
puts %Q / That ' s right/
puts ' escape using " / "'
puts %q/escape using "/"/
end
puts "now is #{
def the(a)
' the ' + a
end
the( ' time ' )
} for all good coders..."
puts " That's right "
puts %Q / That ' s right/
puts ' escape using " / "'
puts %q/escape using "/"/
end
puts "now is #{
def the(a)
' the ' + a
end
the( ' time ' )
} for all good coders..."
输出:
That's right
escape using "/"
That's right
escape using "/"
now is the time for all good coders...
操作字符串