Skip to content

Instantly share code, notes, and snippets.

@supki
Created April 18, 2014 12:08
Show Gist options
  • Save supki/11040663 to your computer and use it in GitHub Desktop.
Save supki/11040663 to your computer and use it in GitHub Desktop.
EBLO
class I
attr_accessor :name
def initialize(name)
self.name = name
end
end
class D < I
attr_accessor :children
def initialize(name, &block)
super(name)
self.children = []
self.instance_eval(&block) if block
end
def directory(name, &block)
self.children << ::U.directory(name, &block)
end
def file(name, opts = {})
self.children << ::U.file(name, opts)
end
end
class F < I
attr_accessor :content
def initialize(name, opts = {})
super(name)
self.content = opts[:content]
end
end
module U
def directory(name, &block)
::D.new(name, &block)
end
def file(name, opts = {})
::F.new(name, opts)
end
end
include U
# Example:
#
# directory("foo") do
# directory("bar")
# directory("baz")
# file("xyz")
# file("xyzzy", content: "boo-hoo")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment