0

creating instance using lambda

 def a_method
    a=lambda { return  "we just returned from the block" }.call
    p a
    return "we just returned from the calling method"
end

puts a_method 

creating instance using proc

def a_method
    a=Proc.new { return  "we just returned from the block" }.call
    print a
    p "we just returned from the calling method"
end

puts a_method

I want to know how this two representations are different??

Community
  • 1
  • 1
  • If you run the code you can see the difference - in the case of the proc, the `return` exits the entire function, not just the content of the proc. Procs share this behavior with blocks – max pleaner Feb 05 '20 at 06:41
  • Quite a few differences: beside `Proc.new` and `lambda`, you have `p` vs. `print`, and `return` vs. `p`. The methods might be easier to compare if you make them more alike. – Stefan Feb 05 '20 at 09:27

0 Answers0