发布新日志

  • 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

Open Toolbar