Class: Metamorpher::Terms::Literal
- Inherits:
-
Term
- Object
- Term
- Metamorpher::Terms::Literal
show all
- Defined in:
- lib/metamorpher/terms/literal.rb
Instance Attribute Summary
Attributes inherited from Term
#parent
Instance Method Summary
collapse
Methods inherited from Term
#alternatives, #path, #with_younger_siblings
#substitute
#replace
#match
Methods included from Visitable
#accept
Constructor Details
#initialize(attributes = {}) ⇒ Literal
Returns a new instance of Literal.
10
11
12
13
|
# File 'lib/metamorpher/terms/literal.rb', line 10
def initialize(attributes = {})
initialize_attributes(attributes)
children.each { |child| child.parent = self }
end
|
Instance Method Details
#branch? ⇒ Boolean
27
28
29
|
# File 'lib/metamorpher/terms/literal.rb', line 27
def branch?
!leaf?
end
|
#child_of?(parent_name) ⇒ Boolean
31
32
33
|
# File 'lib/metamorpher/terms/literal.rb', line 31
def child_of?(parent_name)
parent && parent.name == parent_name
end
|
#children_younger_than_or_equal_to(child) ⇒ Object
35
36
37
|
# File 'lib/metamorpher/terms/literal.rb', line 35
def children_younger_than_or_equal_to(child)
children[(index(child))..-1]
end
|
#inspect ⇒ Object
15
16
17
18
19
20
21
|
# File 'lib/metamorpher/terms/literal.rb', line 15
def inspect
if leaf?
"#{name}"
else
"#{name}(#{children.map(&:inspect).join(', ')})"
end
end
|
#leaf? ⇒ Boolean
23
24
25
|
# File 'lib/metamorpher/terms/literal.rb', line 23
def leaf?
children.empty?
end
|