您好,欢迎来到微智科技网。
搜索
您的当前位置:首页ruby数组与散列表

ruby数组与散列表

来源:微智科技网

%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}





因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- 7swz.com 版权所有 赣ICP备2024042798号-8

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务