Hi --

On Mon, 13 Oct 2008, Kless wrote:

> What advantage or difference has a procedure (Proc) over a method?

A method is executed as a direct result of sending a message to an
object:

   "hello".upcase   # the message is 'upcase', which resolves to a
 		   # method name

A Proc object gets called by sending *it* a message:

   pr = Proc.new { puts "I am a Proc!" }
   pr.call   # prints: I am a Proc!

Every method is defined inside a class or module, and executing the
method depends on having an object that will be able to find the
method. Procs, however, are handed around like other objects: a Proc
you create in one context can be called in another. Procs do not
belong to classes or modules.

There's more, but those are some basic differences.


David

-- 
Rails training from David A. Black and Ruby Power and Light:
   Intro to Ruby on Rails  January 12-15   Fort Lauderdale, FL
   Advancing with Rails    January 19-22   Fort Lauderdale, FL *
   * Co-taught with Patrick Ewing!
See http://www.rubypal.com for details and updates!