class TPPlus::Namespace
Public Class Methods
new(name, block)
click to toggle source
# File lib/tp_plus/namespace.rb, line 3 def initialize(name, block) @name = name @block = block @namespaces = {} @variables = {} @constants = {} define! end
Public Instance Methods
add_constant(identifier, node)
click to toggle source
# File lib/tp_plus/namespace.rb, line 24 def add_constant(identifier, node) raise "Constant (#{identifier}) already defined within namespace #{@name}" unless @constants[identifier.to_sym].nil? @constants[identifier.to_sym] = node end
add_namespace(identifier, block)
click to toggle source
# File lib/tp_plus/namespace.rb, line 30 def add_namespace(identifier, block) if @namespaces[identifier.to_sym].nil? @namespaces[identifier.to_sym] = TPPlus::Namespace.new("#{@name} #{identifier}", block) else @namespaces[identifier.to_sym].reopen!(block) end end
add_var(identifier, node)
click to toggle source
# File lib/tp_plus/namespace.rb, line 38 def add_var(identifier, node) raise "Variable (#{identifier}) already defined within namespace #{@name}" unless @variables[identifier.to_sym].nil? @variables[identifier.to_sym] = node node.comment = "#{@name} #{identifier}" end
define!()
click to toggle source
# File lib/tp_plus/namespace.rb, line 13 def define! @block.flatten.select {|n| [TPPlus::Nodes::DefinitionNode, TPPlus::Nodes::NamespaceNode].include? n.class }.each do |node| node.eval(self) end end
get_constant(identifier)
click to toggle source
# File lib/tp_plus/namespace.rb, line 45 def get_constant(identifier) raise "Constant (#{identifier}) not defined within namespace #{@name}" if @constants[identifier.to_sym].nil? @constants[identifier.to_sym] end
get_namespace(identifier)
click to toggle source
# File lib/tp_plus/namespace.rb, line 58 def get_namespace(identifier) if ns = @namespaces[identifier.to_sym] return ns end false end
get_var(identifier)
click to toggle source
# File lib/tp_plus/namespace.rb, line 51 def get_var(identifier) return get_constant(identifier) if identifier.upcase == identifier raise "Variable (#{identifier}) not defined within namespace #{@name}" if @variables[identifier.to_sym].nil? @variables[identifier.to_sym] end
reopen!(block)
click to toggle source
# File lib/tp_plus/namespace.rb, line 19 def reopen!(block) @block = block define! end