In Ruby a Proc is an object that holds a chunk of code. We can create Proc by ” lambda( )” method. To call the code block we have to use call method of Proc.
And if we want this Proc object to pass as code block argument then we have to append an ‘&’ with Proc name.
One thing to remember that we have to associate an ‘&’ with the parametername to pick up any code block in the method definition. The whole thing is as follows —-
class Report def output_report (&Outputblock) Outputblock.call( ) end end # code-block here with Proc hello = lambda do puts('Hello') puts('I am inside a proc') end report = Report .new report.output_report( &hello)
In the above code “hello” is the created procedure.