[clue] Rake (Ruby) question posted... any experts here?
David L. Anselmi
anselmi at anselmi.us
Thu Dec 8 19:09:47 MST 2011
Lorin Ricker wrote:
> file tar => [src] do |t|
> This is a call (message) to the file object to declare one or more "file
> tasks" using a hash-syntax to pass arguments (tar => [src]) and a block
> parameter (the "|t|"). See any good Ruby primer text, which will also
> tell you that the parentheses which usually surround "function call
> argument list" in other languages can be omitted in Ruby when the
> construct is non-ambiguous (and it is so here)...
> More to the point, the "file tar =>..." method forms a "dependency
> relationship" between a source file (instances of "src") and a target
> file (instances of "tar"). Don't be fooled by the unconventional
> syntax... This is a legal and correct "call" to this method ("file"),
> and I've been staring at the Rake source code to prove it (to myself).
I see--what you're trying to say is that "file" defines a rake task for creating a file.
So as Jacob pointed out, it may not make sense to define that task in the backupTask() method. Does
that cause the definition to happen at run time (so you're dynamically defining it)? Or does it
happen at compile time when tar and src are not assigned? Or does it become a not-task because
within method definition it's interpreted differently?
> I do agree with you that "It (and the lines after) doesn't seem to
> run... Is that a hint?" Well, no. But I agree that, to someone who's
> new to Ruby, things indeed don't "look like they run." Ruby is a very
> *declarative* language...
I didn't mean, "it looks to me like your lines don't run." I meant "your output demonstrates that
these lines don't get run." Since I mistook the file... line for a loop let me rephrase what I said
before: ...[the problem is] in your file task. I think 2 possibilities are likely:
Declaring your file task at run time doesn't get it run. That doesn't surprise me at all and I'm
not sure how possible it is to declare a task at run time and make it a prerequisite for your other
tasks. I think you have to specify your file tasks explicitly (though the prerequisite could be
calculated, and the block could just call a function), or write rules that will synthesize the
If your file task does get run (through sheer good luck) then you've mucked up the block you gave
it. It would seem reasonable that the block has access to tar and src from the enclosing scope (the
FileList block). But you've assigned t and not used it in your block and I find examples of using t
in the block.
I doubt that either of those is explanations is completely accurate. You can find examples of using
t in a file task block and what rules look like at:
More information about the clue