Skip to content

Instantly share code, notes, and snippets.

@teliosdev
Created July 20, 2014 22:50
Show Gist options
  • Save teliosdev/588282404222eb22fab3 to your computer and use it in GitHub Desktop.
Save teliosdev/588282404222eb22fab3 to your computer and use it in GitHub Desktop.
module Liquidscript
module AST
class Node
class << self
# Define a child node for this node. It accepts a name.
#
# @param name [Symbol] the name of the child.
# @return [void]
def child(name)
children << name
attr_accessor(name)
end
# Return an array of the children of this node.
#
# @return [Array<Symbol>]
def children
@_children ||= []
end
end
# Return an array of all of the children of this node.
#
# @return [Array<Node>]
def children
self.class.children.map { |child| send(child) }
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment