Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rake error running task: "undefined method 'Task' for main:Object rake 0.9.2.2

I'm trying to run an example task that I wrote. I've placed the file that contains the code under lib/tasks and named it test.rake.

The task code is:

Task :sayHello do
    puts "Hello World"
end

When I'm trying to run it I get the following error:

/lib/tasks/test.rake:2:in `<top (required)>': undefined method `Task' for main:Object (NoMethodError)
from -e:1:in `load'
from -e:1:in `<main>'

I've tried to run "tools-> Run Rake Task" but I can't find my task within the given tasks. In addition, when I invoke rake -T from the console, my task is not listed.

I googled this error but all the related errors I see occurred in rake 0.9.0.0 and not in 0.9.2.2

I tried to put in inside a namespace and that causes the following error:

undefined method `namespace' for main:Object 

What am I doing wrong here?

like image 308
user429400 Avatar asked May 02 '26 11:05

user429400


1 Answers

It's task (i.e. a method), not Task (i.e. a class). You have to define your task like

task :sayHello do
    puts "Hello World"
end

This matters because Ruby is always case sensitive.

like image 193
Holger Just Avatar answered May 05 '26 03:05

Holger Just