Rake tasks

Contents
Your first task
Describe tasks
Dependencies
Default task

Your first task

Rake reads a file named Rakefile in the current directory and runs the requested task.

A task pairs a name with a block, and rake greet runs the block from the terminal.

task :greet do puts "Hello from Rake" end

rake greet

Hello from Rake

Describe tasks

The desc line documents the task below it for the task list.

Run rake -T to see every described task with its one line summary.

desc "Say hello" task :greet do puts "Hello from Rake" end

rake -T

rake greet # Say hello

Dependencies

Tasks declare prerequisites that run first, which models real build order.

Greet depends on prepare, so preparing always happens before greeting.

task :prepare do puts "Preparing" end task greet: :prepare do puts "Hello from Rake" end

rake greet

Preparing
Hello from Rake

Default task

The default task runs when the command names no task at all.

Point default at greet to make a bare rake call prepare and greet in order.

task :prepare do puts "Preparing" end task greet: :prepare do puts "Hello from Rake" end task default: :greet

rake

Preparing
Hello from Rake

Next: Environment and CLI

Article author: Arthur Isaev

Related articles
Ruby
Ruby course: zero to hero in 50 lessons
What is Ruby and where it runs
Install Ruby and check the version
irb: the interactive shell
Your first Ruby script
Variables
Numbers
Strings
Symbols
Truthiness: only false and nil
Conditions
Loops
Arrays
Hashes
Ranges
Methods
Blocks, procs, lambdas
String tools
Files and IO
Exceptions
Modules and mixins
Classes and objects
Inheritance
Enumerables
Duck typing and core idioms
Gems and Bundler
Testing with Minitest
Debugging
Encodings
Time and date
JSON and YAML
HTTP clients
Sockets
REST APIs
puts, print and p
Metaprogramming
Enumerators
Pattern matching
Arguments: splats and kwargs
Rake tasks
Environment and CLI
Logging
CSV
ERB templates
WEBrick server
Rails in one lesson
Capstone: todo CLI
Capstone: JSON API
Performance
Modern Ruby tour
Hero roadmap: the whole course on one page
Install Ruby on Windows 11
Install Ruby on Ubuntu
Install Ruby on Rocky Linux
Install Ruby on macOS
Install Ruby on FreeBSD
Ruby in Docker
Threads and fibers
Banner image

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.ru
Write to info@urn.su, info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: