return a lambda function : lambda « Method « Ruby






return a lambda function


  def n_times(thing)
    return lambda {|n| thing * n }
  end

  p1 = n_times(23)
  p1.call(3)
  p1.call(4)
  p2 = n_times("Hello ")
  p2.call(3)

 








Related examples in the same category

1.It's possible to store code blocks within variables, using the lambda method
2.Use lambda to create a block
3.Use lambda to create a list of function
4.Invoking Blocks
5.Provide different number of parameters for lambda