Class: DSL::Var

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

Defined Under Namespace

Classes: Table

Constant Summary collapse

PRETTY_PRINT_INSTANCE_VARIABLES =
instance_methods(false).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, arg, &block) ⇒ Var

Returns a new instance of Var.



85
86
87
88
89
# File 'tools/dsl.rb', line 85

def initialize(table, arg, &block)
  @var = table.new_var
  @value = yield arg
  @table = table
end

Instance Attribute Details

#valueObject (readonly)

Returns the value of attribute value.



75
76
77
# File 'tools/dsl.rb', line 75

def value
  @value
end

#varObject (readonly) Also known as: to_s

Returns the value of attribute var.



75
76
77
# File 'tools/dsl.rb', line 75

def var
  @var
end

Instance Method Details

#[](idx) ⇒ Object

Indexing.

$:1 -> v1=get_value($:1)
$:1[0] -> rb_ary_entry(v1, 0)
$:1[0..1] -> [rb_ary_entry(v1, 0), rb_ary_entry(v1, 1)]
*$:1[0..1] -> rb_ary_entry(v1, 0), rb_ary_entry(v1, 1)

Splat needs ‘[range]` because `Var` does not have the length info.



99
100
101
102
103
104
105
# File 'tools/dsl.rb', line 99

def [](idx)
  if ::Range === idx
    idx.map {|i| self[i]}
  else
    @table.fetch("#@var[#{idx}]") {"rb_ary_entry(#{@var}, #{idx})"}
  end
end

#pretty_print_instance_variablesObject



79
80
81
# File 'tools/dsl.rb', line 79

def pretty_print_instance_variables
  PRETTY_PRINT_INSTANCE_VARIABLES
end