On Wednesday 24 March 2010 08:20:06 am David Espada wrote:
> I have a question about procs and methods. Why is not possible to invoke
> them in same form:

Because the syntax for calling a method always calls a method. Let me put it 
this way:

> * proc: foo[param1, param2]
> * method: foo(param1, param2)

The only way you can have something called 'foo' is if there's a local 
variable, or if there's a method with the name 'foo'. For example, if there 
isn't a local variable, your code could be interpreted as:

foo()[param1, param2]

Does that make sense? So right now, this:

foo(param1, param2)

will always call the method 'foo'. With what you're suggesting, it'd have to 
check for a local variable first -- and what would happen if the method 'foo' 
returns a proc, how would I call that? Would I do:

foo()(param1, param2)

Wouldn't that get confusing?

Basically, procs aren't methods, they're objects. When you use that [] syntax, 
you're actually calling the [] method on the foo object. It gets interpreted 
like this:

foo.[](param1, param2)

So these mean fundamentally different things.

Now, you could take a proc and turn it into a method with define_method...