I think you can do this: task 'someTask' do |t| puts t.to_s end
On Fri, Jan 29, 2010 at 07:58, Andrew Moore <[email protected]>wrote: > > Hi, > > I'm a ruby newbie, and I've been using BuildR off and on for a bit > (currently 1.3.3), but I was wondering if there is a way to access the name > of a task that calls a method without passing an argument to that method. > For instance: > > > > def print_task_name() > # print the name of the task that called this function > puts '['+taskName+']' > end > > desc 'my-project' > define 'my-project' > > desc 'taskA' > task 'taskA' do > print_task_name > end > > desc 'taskB' > task 'taskB' > print_task_name > end > > end #my-project > > > > My goal is that if I run: > > buildr my-project:taskA > > that the print_task_name method will print: > > [my-project:taskA] > > I've been searching through the various Rake, Buildr, and Ruby API's and > the > closest I've come is the core ruby 'caller' method. I've spent enough time > trying to figure it out that it's time to ask the experts! > > Is what I'm wanting to do possible without adding an argument to the > print_task_name method? > > Thanks in advance for your help! > > Regards, > > Andrew > > > > > > > > > -- > View this message in context: > http://n2.nabble.com/Task-name-which-called-a-method-tp4480710p4480710.html > Sent from the Apache Buildr - User mailing list archive at Nabble.com. >
