Everyday Scripting with Ruby学习笔记(一)

上一篇 / 下一篇  2007-06-13 22:12:07 / 个人分类:脚本编程

1.When a name begins with a capital letter, you’re telling Ruby that you
expect it always to refer to the same object. Ruby will complain if you
try to use the same name for a different object:
irb(main):007:0> MyShip = "a cutter"
=> "a cutter"
irb(main):008:0> MyShip = "a bark"
(irb):4: warning: already initialized constant MyShip
=> "a bark"
(Ruby complains but still obeys.)

2. Although puts is printing a string, it doesn’t put quotes around
it like irb does. irb’s output is formatted for you, a scrīpter. puts
formats its output for end-user consumption. If you want the irbstyle
output, use the inspect message: inspect
irb(main):010:0> puts "I'd like some quotes, please".inspect
"I'd like some quotes, please"
=> nil


TAG: 脚本编程

 

评分:0

我来说两句

Open Toolbar