Selon David Harrigan <dharrigan / gmail.com>:

>
> Another object simply can't call
> File.openAndProcess("another_testfile", "r") WITHOUT knowing that one
> also has to write a block because inside openAndProcess there is a
> "yield". This means that the method openAndProcess isn't that
> invisible, the callee must have some detailed knowledge about the
> method (i.e., the fact that it calls a yield) so that they can write a
> block.
>
> Am I missing something here?
>

I may be the one missing something here but what is the difference between
knowing that a method needs a block and knowing that it needs any other
parameter? When you want to use a method, you need to know about the number and
kind of parameters it needs, don't you? Well, blocks are just another parameter,
with a special syntax to make the common case of calling just one block nicer
looking and simple to understand. So when you learn the signature of a method
in Ruby, you learn all the parameters it asks for, what they mean, whether they
are mandatory or optional, and that includes a possible block and the arguments
it itself takes.

Frankly, I don't know why having to know that File::open needs two string
parameters containing the name of the file and the opening mode is different
from having to know that it also takes a block which takes the file handle of
the open file as argument. And if you check the API in for instance
http://ruby-doc.org/core, you'll see that the presence of a block (and its
arguments) is described in the API. It's just a method argument. It doesn't
reveal more detail about the method than any other method argument.

Am I missing something here?
--
Christophe Grandsire.

http://rainbow.conlang.free.fr

It takes a straight mind to create a twisted conlang.