Class: DSL::Var::Table

Inherits:
Hash
  • Object
show all
Defined in:
tools/dsl.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ Table

Returns a new instance of Table.



48
49
50
51
52
# File 'tools/dsl.rb', line 48

def initialize(&block)
  super() {|tbl, arg|
    tbl.fetch(arg, &block)
  }
end

Instance Method Details

#add(&block) ⇒ Object



60
61
62
63
# File 'tools/dsl.rb', line 60

def add(&block)
  v = new_var
  self[v] = Var.new(self, v, &block)
end

#defined?(name) ⇒ Boolean

Returns:

  • (Boolean)


65
66
67
68
# File 'tools/dsl.rb', line 65

def defined?(name)
  name = name.to_s
  any? {|_, v| v.var == name}
end

#fetch(arg, &block) ⇒ Object



54
55
56
57
58
# File 'tools/dsl.rb', line 54

def fetch(arg, &block)
  super {
    self[arg] = Var.new(self, arg, &block)
  }
end

#new_varObject



70
71
72
# File 'tools/dsl.rb', line 70

def new_var
  "v#{size+1}"
end