=begin #字符串 #数字, Several classes of numbers: fixnum: The largest integer value that the native machine byte can store, and bignum: An integer value that exceeds the maximum integer value that can be stored by the native machine byte; float: Stores floating-point types; bigdecimal: Provides a floating-point number type of arbitrary precision; numeric: All numbers of sub-classes, all other numeric types =end# strings of some basic methods p "string" #输出结果为: "String" p "string" * 2 #输出结果为: "stringstring" p "String" + "Class" #输出结果为: "Stringclass" "a". ord # Gets the ASCII encoding of the first character of the string: "A" < "B" # Compare the size of ASCII on both sides: true "WA" =~ /a/ #用正则匹配字符在字符串中的位置, starting bit 0:1# Some basic methods of number types 5.times { |x| puts x } #使用 Number of times method, output from 0 to 4 a large five number: 0\n1\n2\n3\n4\n5.times { puts "a" } #使用 times .times method, will "a" continuous output five times: A\na\na\na\na\n5.upto (Ten) { |x| puts x } #使用 Start value. Upto (end value) method for controlling the output range: 5\n6\n7\n8\n9\n10\n10.downto (5) { |x| puts x } #使用 End value. Downto (initial value) Reverse output: 10\n9\n8\n7 \n6\n5\n15.step (50, 8) { |x| puts x } #使用 initial value. Step (end value, stepping value) ) output result, result less than equals end value: 15\n23\n31\n39\n47\n#bigdecimal usage require ' BigDecimal ' a = bigdecimal.new ( "0.07") p (a * 100). to_i
This article is from the "Invite the Wind" blog, please be sure to keep this source http://yaoyuechengfeng.blog.51cto.com/2958475/1729115
ruby-Numbers & Strings