# Doubt when nesting tasks in Rakefile

**URL:** <https://rubytalk.org/t/doubt-when-nesting-tasks-in-rakefile/65249>\
**Category:** ruby-talk\
**Created:** [12 April 2012 11:31 UTC](https://rubytalk.org/t/doubt-when-nesting-tasks-in-rakefile/65249 "2012-04-12T11:31:57Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![7stud2](https://avatars.discourse-cdn.com/v4/letter/7/9de053/32.png) [@7stud2](https://rubytalk.org/u/7stud2)\
**Post date:** [12 April 2012 11:31 UTC](https://rubytalk.org/t/doubt-when-nesting-tasks-in-rakefile/65249/1 "2012-04-12T11:31:57Z")

</div>

Hello,

I'm checking some implemented code and I've seen something like that:

----------------------- RAKEFIKE ---------------------------------

$:.unshift File.dirname(\_\_FILE\_\_)+"/rake"  
require 'rake'  
require 'rakeTest'

task :default =\> [:Where, RakeTasks.create]  
task :Where do  
&nbsp;&nbsp;puts "Welcome to the rakefile"  
end

------------------- TESTFILE ------------------------------------

module RakeTasks

&nbsp;&nbsp;def self.create  
&nbsp;&nbsp;&nbsp;&nbsp;puts "--Execute task1"  
&nbsp;&nbsp;&nbsp;&nbsp;Task1.create  
&nbsp;&nbsp;&nbsp;&nbsp;puts "--Execute task2"  
&nbsp;&nbsp;&nbsp;&nbsp;Task2.create  
&nbsp;&nbsp;&nbsp;&nbsp;task :end =\>[:die]  
&nbsp;&nbsp;end

&nbsp;&nbsp;module Task1  
&nbsp;&nbsp;&nbsp;&nbsp;def self.create  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "Hello World"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;task :die do  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "I want to die"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end

&nbsp;&nbsp;module Task2  
&nbsp;&nbsp;&nbsp;&nbsp;def self.create  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts "I'm growing"  
&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;end

end

> **···**
>
> ---------------------------------------------------------------
> 
> The output for that is:
> 
> c:\Programs\checkingRuby\>rake  
> (in c:/Programs/checkingRuby)  
> --Execute task1  
> Hello World  
> --Execute task2  
> I'm growing  
> Welcome to the rakefile  
> I want to die
> 
> But with the same test file only modifying the Rakefile as follows:
> 
> ----------------------- RAKEFIKE ---------------------------------
> 
> $:.unshift File.dirname(\_\_FILE\_\_)+"/rake"  
> require 'rake'  
> require 'rakeTest'
> 
> task :default =\> [:Where,RakeTasks.create,RakeTasks::Task1.create]  
> task :Where do  
> &nbsp;&nbsp;puts "Welcome to the rakefile"  
> end  
> -------------------------------------------------------------------
> 
> The output is:
> 
> c:\Programs\checkingRuby\>rake  
> (in c:/Programs/checkingRuby)  
> --Execute task1  
> Hello World  
> --Execute task2  
> I'm growing  
> Hello World  
> Welcome to the rakefile  
> I want to die  
> I want to die
> 
> So, I don't understand how the calls are queued before being executed.  
> In both cases it starts with the classes task1 and task2 but the task  
> Where is executed always after the classes even though the call inside  
> the hash is declared before, same case is happening with the execution  
> of the task die although it is defined at the end of the hash.
> 
> Could anybody explain me how ruby is queuing or organizing the tasks or  
> just attach a reference to be reviewed? The only documentation I found  
> didn't take into account nested tasks execution.
> 
> Thanks a lot!
> 
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
