📝 Edit page
➕ Add page
Basic
Intro to using rake and Rakefile for Ruby projects
Rake is a Ruby task runner. You run the rake
command with arguments and the tasks to run are defined in a Rakefile
which has Ruby code in it.
Samples
Hello world
Based on the blog post on the RubyGuides site.
Rakefile
desc "Print a greeting." task :greet do puts "Hello, world!" end
How to run it:
$ rake greet
"Hello, world!"
Task types
See the Rakefile format tutorial - it covers the syntax. Only minimal examples are shown below as these are too generic to be useful as is.
Rakefile
# Simple. task :name puts 'Hello, world!' end # With arguments. task :name do |t, args| puts "Hello, #{args.name}!" end # With prerequisites. task name: [:prereq1, :prereq2] do |t| puts t end # Alt # task :name, [:first_name, :last_name] do |t, args| # ...
Compile C - from Wikipedia
From the Rake page on Wikipedia.
Compile a Hello World program in C.
file 'hello.o' => 'hello.c' do
sh 'cc -c -o hello.o hello.c'
end
file 'hello' => 'hello.o' do
sh 'cc -o hello hello.o'
end
Rules:
rule '.o' => '.c' do |t|
sh "cc #{t.source} -c -o #{t.name}"
end