ruby的lambda

作者: 孤独的猫
发布时间:2015-07-13 11:24:23

irb(main):012:0> def n_times(thing)
irb(main):013:1>    return lambda {|n| thing * n}
irb(main):014:1> end
=> nil
irb(main):015:0> p1=n_times(23)
=> #<Proc:0xb77281f4@(irb):13>
irb(main):016:0> p1.call(3)
=> 69
irb(main):017:0> p1.call(4)
=> 92
irb(main):018:0> p2=n_times("Hello ")
=> #<Proc:0xb77281f4@(irb):13>
irb(main):019:0> p2.call(3)
=> "Hello Hello Hello "
irb(main):020:0>

标签: Lambda Ruby
来源:http://www.cnblogs.com/djcsch2001/archive/2012/03/24/2415954

推荐: