Class: Metamorpher::Terms::Literal

Inherits:
Term
  • Object
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

Methods included from Rewriter::Substitution

#substitute

Methods included from Rewriter::Replacement

#replace

Methods included from Matcher::Matching

#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

Returns:

  • (Boolean)


27
28
29
# File 'lib/metamorpher/terms/literal.rb', line 27

def branch?
  !leaf?
end

#child_of?(parent_name) ⇒ Boolean

Returns:

  • (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

#inspectObject



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

Returns:

  • (Boolean)


23
24
25
# File 'lib/metamorpher/terms/literal.rb', line 23

def leaf?
  children.empty?
end