Class: Spektr::Exp::Argument

Inherits:
Base
  • Object
show all
Defined in:
lib/spektr/exp/send.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#arguments, #body, #location, #options

Instance Method Summary collapse

Methods inherited from Base

#handler_missing, #process, #send?

Constructor Details

#initialize(ast) ⇒ Argument

Returns a new instance of Argument.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/spektr/exp/send.rb', line 37

def initialize(ast)
  @name = nil
  process_ast(ast)
  ast = ast.children.first if ast.type == :begin
  @ast = ast
  argument = if %i[xstr hash].include? ast.type
               ast
             elsif ast.type != :dstr && ast.children.first.is_a?(Parser::AST::Node) && ast.children.first.children.first.is_a?(Parser::AST::Node)
               ast.children.first.children.first
             elsif ast.type != :dstr && ast.children.first.is_a?(Parser::AST::Node)
               ast.children.first
             else
               ast
             end
  @type = argument.type
  @children = argument.children
end

Instance Attribute Details

#astObject

Returns the value of attribute ast.



35
36
37
# File 'lib/spektr/exp/send.rb', line 35

def ast
  @ast
end

#childrenObject

Returns the value of attribute children.



35
36
37
# File 'lib/spektr/exp/send.rb', line 35

def children
  @children
end

#nameObject

Returns the value of attribute name.



35
36
37
# File 'lib/spektr/exp/send.rb', line 35

def name
  @name
end

#typeObject

Returns the value of attribute type.



35
36
37
# File 'lib/spektr/exp/send.rb', line 35

def type
  @type
end

Instance Method Details

#on_begin(node) ⇒ Object



59
60
61
# File 'lib/spektr/exp/send.rb', line 59

def on_begin(node)
  process_all(node)
end

#on_const(node) ⇒ Object



71
72
73
# File 'lib/spektr/exp/send.rb', line 71

def on_const(node)
  @name ||= node.children[1] if node.children.first.nil?
end

#on_send(node) ⇒ Object



63
64
65
66
67
68
69
# File 'lib/spektr/exp/send.rb', line 63

def on_send(node)
  if node.children.first.nil?
    @name ||= node.children[1]
  elsif node.is_a?(Parser::AST::Node)
    process_all(node)
  end
end

#on_str(node) ⇒ Object Also known as: on_sym, on_ivar



75
76
77
# File 'lib/spektr/exp/send.rb', line 75

def on_str(node)
  @name ||= node.children.first
end

#process_ast(ast) ⇒ Object



55
56
57
# File 'lib/spektr/exp/send.rb', line 55

def process_ast(ast)
  process(ast)
end