Where and when to use Lambda?

后端 未结 7 2030
执笔经年
执笔经年 2021-01-31 16:47

I am trying to understand why do we really need lambda or proc in ruby (or any other language for that matter)?

#method
def add a,b
  c = a+b
end

#using proc
de         


        
7条回答
  •  终归单人心
    2021-01-31 17:40

    In case of OOP, you should create a function in a class only if there should be such an operation on the class according to your domain modeling.

    If you need a quick function which can be written inline such as for comparison etc, use a lambda

    Also check these SO posts -

    When to use lambda, when to use Proc.new?

    C# Lambda expressions: Why should I use them?

    When to use a lambda in Ruby on Rails?

提交回复
热议问题