Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Ruby Rake Task Methods
# -----------
# In reference to:
# http://www.albertoalmagro.com/ruby-methods-defined-in-rake-tasks/
# -----------
# Rakefile
# Load tasks
Dir.glob('*.rake').each do |path|
load path
end
# -----------
# foo.rake
desc 'foo task'
task :foo do
def greet
puts 'Hello from foo.rake'
end
puts 'In foo task'
greet
end
#-------------
# bar.rake
desc 'bar task'
task :bar do
def greet
puts 'Hello from bar.rake'
end
puts 'In bar task'
greet
end
#-----------
# Output
# $ rake -T
# rake bar # bar task
# rake foo # foo task
# $ rake foo
# In foo task
# Hello from foo.rake
# $ rake bar
# In bar task
# Hello from bar.rake
@albertoalmagro

This comment has been minimized.

Copy link

@albertoalmagro albertoalmagro commented Jun 12, 2019

Thanks for this tip! I'm editing the post to add it 👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.