孤独的猫

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

%q中定义的字符串,不加分号  如'hello'与%q(hello)  表示同一字符串

%w表示数组,不对变量进行替换;%W表示数组,对变量进行替换

散列表用=>序列进行分隔

irb(main):001:0> %w(fred wilma barney betty great\ gazoo)
=> ["fred", "wilma", "barney", "betty", "great gazoo"]
irb(main):002:0> arr=%w(fred wilma barney betty great\ gazoo)
=> ["fred", "wilma", "barney", "betty", "great gazoo"]
irb(main):003:0> 'hello'
=> "hello"
irb(main):004:0> "hello"
=> "hello"
irb(main):005:0> %q(hello)
=> "hello"
irb(main):006:0> %w(Hey! #{Time.now})
=> ["Hey!", "\#{Time.now}"]
irb(main):007:0> %W(Hey! #{Time.now})
=> ["Hey!", "Sun Mar 25 20:51:48 +0800 2012"]

irb(main):012:0> colors={  "red" => 0xf00,
irb(main):013:1*             "green" => 0x0f0,
irb(main):014:1*             "blue" => 0x00f
irb(main):015:1>          }
=> {"blue"=>15, "green"=>240, "red"=>3840}





posted on 2012-03-25 20:57  孤独的猫  阅读(281)  评论(0编辑  收藏  举报