Skip to content

Instantly share code, notes, and snippets.

@archan937
Created January 8, 2014 10:49
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save archan937/8314966 to your computer and use it in GitHub Desktop.
Save archan937/8314966 to your computer and use it in GitHub Desktop.
Override Rake::Task.define_task for cleaner arguments passing
require_relative "task"
desc "Send an invite"
task :invite do |name, email|
puts "Invitation sent to '#{name} <#{email}>'"
end
# Example:
#
# $ rake invite "Paul Engel" paul@engel.com
# Invitation sent to 'Paul Engel <paul@engel.com>'
#
module Rake
class Task
class << self
alias :original_define_task :define_task
end
def self.define_task(*args, &block)
original_define_task *args do |task|
if block_given?
arguments = ARGV.select do |arg|
!arg.include?(task.name) && original_define_task(arg.to_sym) do; end
end
block.call *arguments
end
end
end
end
end
@salient1
Copy link

Nicely done, sir!

@blvz
Copy link

blvz commented Apr 8, 2014

Nicely done, indeed.
Rake::Task['invite'].invoke 'Paul Engel', 'paul@engel.com' don't work, though. :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment