Class: Solargraph::Parser::Rubyvm::NodeChainer

Inherits:
Object
  • Object
show all
Includes:
NodeMethods
Defined in:
lib/solargraph/parser/rubyvm/node_chainer.rb

Overview

A factory for generating chains from nodes.

Constant Summary collapse

Chain =
Source::Chain

Class Method Summary collapse

Instance Method Summary collapse

Methods included from NodeMethods

any_splatted_call?, call_nodes_from, const_nodes_from, convert_hash, find_recipient_node, infer_literal_node_type, node?, pack_name, returns_from, splatted_call?, splatted_hash?, splatted_node?, unpack_name

Constructor Details

#initialize(node, filename = nil, in_block = false) ⇒ NodeChainer

Returns a new instance of NodeChainer.

Parameters:

  • node (Parser::AST::Node)
  • filename (String) (defaults to: nil)


15
16
17
18
19
# File 'lib/solargraph/parser/rubyvm/node_chainer.rb', line 15

def initialize node, filename = nil, in_block = false
  @node = node
  @filename = filename
  @in_block = in_block ? 1 : 0
end

Class Method Details

.chain(node, filename = nil, in_block = false) ⇒ Source::Chain

Parameters:

  • node (Parser::AST::Node)
  • filename (String) (defaults to: nil)

Returns:



31
32
33
# File 'lib/solargraph/parser/rubyvm/node_chainer.rb', line 31

def chain node, filename = nil, in_block = false
  NodeChainer.new(node, filename, in_block).chain
end

.load_string(code) ⇒ Source::Chain

Parameters:

  • code (String)

Returns:



37
38
39
40
41
42
# File 'lib/solargraph/parser/rubyvm/node_chainer.rb', line 37

def load_string(code)
  node = Parser.parse(code.sub(/\.$/, ''))
  chain = NodeChainer.new(node).chain
  chain.links.push(Chain::Link.new) if code.end_with?('.')
  chain
end

Instance Method Details

#chainSource::Chain

Returns:



22
23
24
25
# File 'lib/solargraph/parser/rubyvm/node_chainer.rb', line 22

def chain
  links = generate_links(@node)
  Chain.new(links, @node, (Parser.is_ast_node?(@node) && @node.type == :SPLAT))
end