Created
August 4, 2020 15:34
-
-
Save devnull255/81f1387402bef514285591bfe678c87e to your computer and use it in GitHub Desktop.
Toy rake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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