Is tap in buildr different from Kernel#tap? If not then your explanation is a bit misleading.
Invoking tap on an object simply yields that object to the block and returns that object. I use this now and then to create a new scope which avoids cluttering methods with local variables. See http://ruby-doc.org/core-2.0/Object.html#method-i-tap for details. Pepijn Op 23-mei-2013 om 17:23 heeft Antoine Toulme <[email protected]> het volgende geschreven: > This is more of a Rake question actually. Rake provides ways for you to > define tasks. > So when you type task(:compile) do |task| ... you are actually redefining > the compile task. That's why it's doing nothing. > > Rake provides a way to define task dependencies as tasks. Buildr builds on > this by adding the tap method which lets you add a dependent task directly > on the compile task. tap inserts the dependency as the first item in the > list, so if you tap twice, the second time will execute before the first > time. > > I hope this helps. > > > On Thu, May 23, 2013 at 6:11 AM, Adam George <[email protected]> wrote: > >> Hi, >> >> I'm relatively new to Buildr/Ruby and whilst I'm getting the hang of most >> things there is still one thing that I don't understand. >> >> Consider this: >> >> # example 1 (seems to do nothing) >> task(:compile) do |task| >> task.sources = [path_to(:source, :main, :catalina)] >> task.with "org.apache.tomcat:tomcat-catalina:jar:7.0.35", >> "javax.servlet:servlet-api:jar:2.5" >> task.into(_(:target, :classes, :catalina)) >> end >> >> ... and this: >> >> # example 2 (works as expected) >> task(:compile).tap do |task| >> task.sources = [path_to(:source, :main, :catalina)] >> task.with "org.apache.tomcat:tomcat-catalina:jar:7.0.35", >> "javax.servlet:servlet-api:jar:2.5" >> task.into(_(:target, :classes, :catalina)) >> end >> >> Both code blocks receive a task argument that identifies itself as >> "my_project:compile" when printed to the console, but I can't understand >> why >> the enhancement in example 1 does nothing to the compile task of >> my_project. >> >> I'm comfortable with the fact that I need to use .tap, but I don't really >> understand why it's necessary. If both functions are given the same >> argument >> at run time, why does only the second example work? What is happening in >> example 1 in this case? >> >> Thanks and regards, >> >> Adam George >> >>
