What is the difference between lambdas and procs? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

What is the difference between lambdas and procs?

4th Mar 2017, 9:00 AM
Emmanuel Nuotah
2 Answers
+ 9
proc = Proc.new do |x| puts "Hi #{x}" end lamb = lambda {puts "Hi #{x}"} proc.call "Bob" #Outputs: Hi Bob lamb.call "David" #Outputs: Hi David proc.call #Outputs: Hi lamb.call #Outputs: Error given arguement(Expected 1, given 0) #Both are the same but when proc expects an arguement but you gave none, then it just outputs the Proc and a nil value. However in lambda when it expects an arguement and you give nothing then it outputs an error.
5th Mar 2017, 12:08 AM
MrCoder
MrCoder - avatar
0
We create lambda when we only need a single line code for make a simple function
7th Jun 2019, 5:09 PM
ardsc
ardsc - avatar