The best resources for developers

When to use lambda and

def whowouldwin

  mylambda = lambda {return "Freddy"}

  # mylambda gets called and returns "Freddy", and execution
  # continues on the next line

  return "Jason"


#=> "Jason"
def whowouldwin2

  myproc = {return "Freddy"}

  # myproc gets called and returns "Freddy", 
  # but also returns control from whowhouldwin2!
  # The line below *never* gets executed.

  return "Jason"


#=> "Freddy"

Tags: ruby lambda proc

Source: By Michiel de Mare as answer to the question

This code snippet was collected from stackoverflow, and is licensed under CC BY-SA 3.0

Related code-snippets: