Skip to content

Instantly share code, notes, and snippets.

@devnull255
Created August 4, 2020 15:34
Show Gist options
  • Save devnull255/81f1387402bef514285591bfe678c87e to your computer and use it in GitHub Desktop.
Save devnull255/81f1387402bef514285591bfe678c87e to your computer and use it in GitHub Desktop.
Toy rake
#!/usr/bin/env ruby
###########################
# mike is a toy rake
class Task
@@tasks = {}
@action = nil
def initialize(n,&action)
@name = n
if ! @@tasks.include? n
@@tasks[n] = self
end
if action
@action = action
end
end
def name
@name
end
def run
puts "TASK: #{self.name}"
@action.call(self)
end
end
def task(name, &block)
t = Task.new(name) { block.call(t) }
t.run
end
task :hello do |t|
puts "greetings from #{t.name}"
end
task :get_file do |t|
puts "running #{t.name}"
end
task :cleanup do |t|
puts "cleaning files"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment