D
David Harrigan
Hi,
I'm getting my head around blocks, closures etc in Ruby - I'm from a
Java background. Now, I'm reading the book "Programming Ruby - The
Pragmatic Programmer's Guide" and in the section titled "Blocks for
Transactions" there is an example of using a block for a file
operation. However, examining this code, and especially with a view of
hiding detail from a receiver, I find myself in some puzzlement,
because of this reason:
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?
-=david=-
I'm getting my head around blocks, closures etc in Ruby - I'm from a
Java background. Now, I'm reading the book "Programming Ruby - The
Pragmatic Programmer's Guide" and in the section titled "Blocks for
Transactions" there is an example of using a block for a file
operation. However, examining this code, and especially with a view of
hiding detail from a receiver, I find myself in some puzzlement,
because of this reason:
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?
-=david=-