码迷,mamicode.com
首页 > 其他好文 > 详细

有趣的程序

时间:2014-08-29 18:18:48      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:ar   2014   sp   amp   c   ef   程序   as   bs   



1.to_proc


class Array
  def to_proc
    proc { |receiver| receiver.send *self }
  end
end


[ 'Hello', 'Goodbye' ].map &[ :+, ' BeiJing!' ]

#=> ["Hello BeiJing!", "Goodbye BeiJing!"]


receiver -> [ ‘Hello‘, ‘Goodbye‘ ]

*self -> [ :+, ‘ BeiJing!‘ ]


2.map(&:key)


order_records = OrderRecord.all(:all, :limit => 10)

order_records.map(&:order_no)

#=> ["20140627141050-5096zG", "20140627143533-90bm9v", "20140627143648-2sJQxR", "20140627161046-UE0y07", "20140627161456-16GGT1", "20140627161707-58Lc3t", "20140627173915-0mI1Ji", "20140627175248-31YTtk", "20140627180802-s487cX", "20140717112957-eQ993g"]








有趣的程序

标签:ar   2014   sp   amp   c   ef   程序   as   bs   

原文地址:http://blog.csdn.net/menxu_work/article/details/38928445

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!