Class: Dentaku::AST::Access
- Inherits:
-
Node
- Object
- Node
- Dentaku::AST::Access
show all
- Defined in:
- lib/dentaku/ast/access.rb
Constant Summary
Constants inherited
from Node
Node::STATIC_CONTEXT, Node::STATIC_MODE_KEY
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Node
#name, precedence, #pure?, resolve_class
Constructor Details
#initialize(data_structure, index) ⇒ Access
Returns a new instance of Access.
21
22
23
24
|
# File 'lib/dentaku/ast/access.rb', line 21
def initialize(data_structure, index)
@structure = data_structure
@index = index
end
|
Instance Attribute Details
#index ⇒ Object
Returns the value of attribute index.
7
8
9
|
# File 'lib/dentaku/ast/access.rb', line 7
def index
@index
end
|
#structure ⇒ Object
Returns the value of attribute structure.
7
8
9
|
# File 'lib/dentaku/ast/access.rb', line 7
def structure
@structure
end
|
Class Method Details
.arity ⇒ Object
9
10
11
|
# File 'lib/dentaku/ast/access.rb', line 9
def self.arity
2
end
|
.max_param_count ⇒ Object
17
18
19
|
# File 'lib/dentaku/ast/access.rb', line 17
def self.max_param_count
arity
end
|
.min_param_count ⇒ Object
13
14
15
|
# File 'lib/dentaku/ast/access.rb', line 13
def self.min_param_count
arity
end
|
Instance Method Details
#accept(visitor) ⇒ Object
50
51
52
|
# File 'lib/dentaku/ast/access.rb', line 50
def accept(visitor)
visitor.visit_access(self)
end
|
#dependencies(context = {}) ⇒ Object
42
43
44
|
# File 'lib/dentaku/ast/access.rb', line 42
def dependencies(context = {})
@structure.dependencies(context) + @index.dependencies(context)
end
|
#type ⇒ Object
46
47
48
|
# File 'lib/dentaku/ast/access.rb', line 46
def type
nil
end
|
#value(context = {}) ⇒ Object
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/dentaku/ast/access.rb', line 26
def value(context = {})
structure = @structure.value(context)
index = @index.value(context)
unless structure.respond_to?(:[]) && !structure.is_a?(::Numeric)
raise Dentaku::ArgumentError.for(:incompatible_type, actual: structure),
"#{self.class} requires an indexable structure, but got #{structure.class}"
end
begin
structure[index]
rescue ::TypeError => e
raise Dentaku::ArgumentError.for(:incompatible_type, actual: index), e.message
end
end
|