Answer 1
irb(main):001:0> lambda_a = lambda do |x| irb(main):002:1* lambda do |y| irb(main):003:2* puts "Hello #{x} #{y}" irb(main):004:2> end irb(main):005:1> lambda do |z| irb(main):006:2* puts "Goodbye #{x} #{z}" irb(main):007:2> end irb(main):008:1> end => #<Proc:0x22864c0@(irb):1 (lambda)> irb(main):009:0> lambda_a.(1).(2) Goodbye 1 2 => nil
Answer 2
irb(main):010:0> lambda_b = lambda do |x| irb(main):011:1* lambda do |y| irb(main):012:2* puts "Hello #{x} #{y}" irb(main):013:2> end irb(main):014:1> lambda do |z, zz| irb(main):015:2* puts "Goodbye #{x} #{z} #{zz}" irb(main):016:2> end irb(main):017:1> end => #<Proc:0x20c2fe0@(irb):10 (lambda)> irb(main):018:0> lambda_b.(1).(2) ArgumentError: wrong number of arguments (1 for 2) from (irb):18:in `call' from (irb):18 from C:/ruby-1.9.1/bin/irb:12:in `<main>'
No comments:
Post a Comment