I’m new to programming, and ruby is my first real run at it. I get blocks, but procs seem like a light method/function concept — why use them? Why not just use a method?
Thanks for your help.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Proc is a callable piece of code. You can store it in a variable, pass as an argument and otherwise treat it as a first-class value.
Depends on what you mean by “method” here.
In this code snippet usage of method
baris pretty limited. You can call it, and that’s it. However, if you wanted to store a reference to it (to pass somewhere else and there call it), you can do this:Here
bar_methodis very similar to lambda (which is similar to Proc).bar_methodis a first-class citizen,f.baris not.For more information, read the article mentioned by @minitech.