programmingruby:Programming Ruby 读书笔记( 3)

  Ruby标准类型:

  A.数字

Test
  
 3.times    { pr "X " }
 1.upto(5)   { |i| pr i, " " }
 99.downto(95) { |i| pr i, " " }
 50.step(80,5) { |i| pr 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.

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..."


  输出:

That's right
escape using ""
That's right
escape using ""
now is the time for all good coders...


  操作

Tags:  programmingruby

延伸阅读

最新评论

发表评论