贴一段代码

上一篇 / 下一篇  2007-08-03 13:00:10 / 个人分类:rails

贴一段代码,其中用到了rails对Symbol的扩展,和!结尾方法的特殊含义:

E:\ruby\demo>ruby script\console
Loading development environment.
>> a = %w{word work world}
=> ["word", "work", "world"]
>> a.collect {|w| w.upcase}
=> ["WORD", "WORK", "WORLD"]
>> a
=> ["word", "work", "world"]
>> a.collect(&:upcase)
=> ["WORD", "WORK", "WORLD"]
>> a
=> ["word", "work", "world"]
>> a.collect!(&:upcase)
=> ["WORD", "WORK", "WORLD"]
>> a
=> ["WORD", "WORK", "WORLD"]


TAG: rails

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-11-21  
      1
2345678
9101112131415
16171819202122
23242526272829
30      

数据统计

  • 访问量: 1533
  • 日志数: 18
  • 建立时间: 2007-07-24
  • 更新时间: 2008-05-13

RSS订阅

Open Toolbar