Class: Leftovers::AST::Node

Inherits:
Parser::AST::Node
  • Object
show all
Defined in:
lib/leftovers/ast/node.rb

Instance Method Summary collapse

Constructor Details

#initialize(type, children = [], properties = {}) ⇒ Node

Returns a new instance of Node.



8
9
10
11
12
13
14
# File 'lib/leftovers/ast/node.rb', line 8

def initialize(type, children = [], properties = {})
  # ::AST::Node#initialize freezes itself.
  # so can't use normal memoizations
  @memo = {}

  super
end

Instance Method Details

#argumentsObject



90
91
92
# File 'lib/leftovers/ast/node.rb', line 90

def arguments
  nil
end

#as_arguments_listObject



86
87
88
# File 'lib/leftovers/ast/node.rb', line 86

def as_arguments_list
  @memo[:as_arguments_list] ||= [self]
end

#block_given?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/leftovers/ast/node.rb', line 110

def block_given?
  false
end

#firstObject



26
27
28
# File 'lib/leftovers/ast/node.rb', line 26

def first
  children.first
end

#hash?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/leftovers/ast/node.rb', line 74

def hash?
  false
end

#kwargsObject



102
103
104
# File 'lib/leftovers/ast/node.rb', line 102

def kwargs
  nil
end

#nameObject



106
107
108
# File 'lib/leftovers/ast/node.rb', line 106

def name
  nil
end

#parentObject



46
47
48
# File 'lib/leftovers/ast/node.rb', line 46

def parent
  @memo[:parent]
end

#parent=(value) ⇒ Object



50
51
52
# File 'lib/leftovers/ast/node.rb', line 50

def parent=(value)
  @memo[:parent] = value
end

#pathObject



34
35
36
# File 'lib/leftovers/ast/node.rb', line 34

def path
  loc.expression.source_buffer.name
end

#positional_argumentsObject



94
95
96
# File 'lib/leftovers/ast/node.rb', line 94

def positional_arguments
  nil
end

#privacyObject



42
43
44
# File 'lib/leftovers/ast/node.rb', line 42

def privacy
  @memo[:privacy] || :public
end

#privacy=(value) ⇒ Object



38
39
40
# File 'lib/leftovers/ast/node.rb', line 38

def privacy=(value)
  @memo[:privacy] = value
end

#proc?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/leftovers/ast/node.rb', line 78

def proc?
  false
end

#receiverObject



98
99
100
# File 'lib/leftovers/ast/node.rb', line 98

def receiver
  nil
end

#scalar?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/leftovers/ast/node.rb', line 58

def scalar?
  false
end

#secondObject



30
31
32
# File 'lib/leftovers/ast/node.rb', line 30

def second
  children[1]
end

#sym?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/leftovers/ast/node.rb', line 82

def sym?
  false
end

#to_literal_sObject



70
71
72
# File 'lib/leftovers/ast/node.rb', line 70

def to_literal_s
  nil
end

#to_sObject



62
63
64
# File 'lib/leftovers/ast/node.rb', line 62

def to_s
  ''
end

#to_scalar_valueObject



54
55
56
# File 'lib/leftovers/ast/node.rb', line 54

def to_scalar_value
  nil
end

#to_symObject



66
67
68
# File 'lib/leftovers/ast/node.rb', line 66

def to_sym
  :''
end

#updated(type = nil, children = nil, properties = nil) ⇒ Object

This is called by ::Parser::AST internals



17
18
19
20
21
22
23
24
# File 'lib/leftovers/ast/node.rb', line 17

def updated(type = nil, children = nil, properties = nil) # leftovers:keep
  maybe_copy = super

  class_for_type = Builder.node_class(maybe_copy.type)
  return maybe_copy if maybe_copy.instance_of?(class_for_type)

  class_for_type.new(maybe_copy.type, maybe_copy.children, location: maybe_copy.loc)
end