lambda与proc的区别

在一个方法中,lambda被call之后会返回都方法本身,而proc被call之后就会直接返回

def batman_ironman_proc
  victor = Proc.new { return "Batman will win!" }
  victor.call
  "Iron Man will win!"
end

puts batman_ironman_proc

def batman_ironman_lambda
  victor = lambda { return "Batman will win!" }
  victor.call
  "Iron Man will win!"
end

puts batman_ironman_lambda

运行的结果是

Batman will win!

Iron Man will win! 

==> nil

你可能感兴趣的:(lambda与proc的区别)