Class: Spektr::Exp::Receiver
- Inherits:
-
Object
- Object
- Spektr::Exp::Receiver
- Defined in:
- lib/spektr/exp/send.rb
Instance Attribute Summary collapse
-
#ast ⇒ Object
Returns the value of attribute ast.
-
#children ⇒ Object
Returns the value of attribute children.
-
#expanded ⇒ Object
Returns the value of attribute expanded.
-
#name ⇒ Object
Returns the value of attribute name.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
- #expand!(ast, tree = []) ⇒ Object
-
#initialize(ast) ⇒ Receiver
constructor
A new instance of Receiver.
- #set_attributes(ast) ⇒ Object
Constructor Details
#initialize(ast) ⇒ Receiver
Returns a new instance of Receiver.
100 101 102 103 |
# File 'lib/spektr/exp/send.rb', line 100 def initialize(ast) @children = [] set_attributes(ast) end |
Instance Attribute Details
#ast ⇒ Object
Returns the value of attribute ast.
98 99 100 |
# File 'lib/spektr/exp/send.rb', line 98 def ast @ast end |
#children ⇒ Object
Returns the value of attribute children.
98 99 100 |
# File 'lib/spektr/exp/send.rb', line 98 def children @children end |
#expanded ⇒ Object
Returns the value of attribute expanded.
98 99 100 |
# File 'lib/spektr/exp/send.rb', line 98 def @expanded end |
#name ⇒ Object
Returns the value of attribute name.
98 99 100 |
# File 'lib/spektr/exp/send.rb', line 98 def name @name end |
#type ⇒ Object
Returns the value of attribute type.
98 99 100 |
# File 'lib/spektr/exp/send.rb', line 98 def type @type end |
Instance Method Details
#expand!(ast, tree = []) ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/spektr/exp/send.rb', line 125 def (ast, tree = []) if ast.is_a?(Parser::AST::Node) && ast.children.any? tree << ast.children.last (ast.children.first, tree) else tree.reverse.join('.') end end |
#set_attributes(ast) ⇒ Object
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/spektr/exp/send.rb', line 105 def set_attributes(ast) if [:begin].include?(ast.type) && ast.children[0].is_a?(Parser::AST::Node) return set_attributes(ast.children[0]) end @ast = ast if ast.type == :dstr @type = :dstr @name = ast.children[0].children.first ast.children[1..].each do |ch| @children << Receiver.new(ch) end else @expanded = (ast) @ast = ast.type == :send && ast.children[0].is_a?(Parser::AST::Node) ? ast.children[0] : ast @type = @ast.type @name = @ast.children.last end end |