Skip to content

Instantly share code, notes, and snippets.

@apeiros
Created February 23, 2014 11:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save apeiros/9170067 to your computer and use it in GitHub Desktop.
Save apeiros/9170067 to your computer and use it in GitHub Desktop.
class Namespace
def initialize(current=[], &block)
@current = current
instance_eval(&block)
end
def namespace(name, &block)
Namespace.new(@current+[name], &block)
end
def task(klass, name)
klass.new(@current+[name])
end
end
class Task
def initialize(name)
@name = name
puts "Defined a #{self.class} as #{@name.join(':')}"
end
end
class TaskX < Task; end
class TaskZ < Task; end
def root(&block)
Namespace.new(&block)
end
root do
task TaskX, :foo
namespace :bar do
task TaskZ, :quuz
end
task Task, :blabber
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment