Class: RubyVM::AbstractSyntaxTree::NodeWrapper

Inherits:
SimpleDelegator
  • Object
show all
Defined in:
lib/solargraph/parser/rubyvm/node_wrapper.rb

Overview

Wrapper for RubyVM::AbstractSyntaxTree::Node. for return character based column

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, code) ⇒ NodeWrapper

Returns a new instance of NodeWrapper.

Parameters:



9
10
11
12
# File 'lib/solargraph/parser/rubyvm/node_wrapper.rb', line 9

def initialize(node, code)
  @code = code
  super(node)
end

Instance Attribute Details

#codeObject (readonly)

Returns the value of attribute code.



6
7
8
# File 'lib/solargraph/parser/rubyvm/node_wrapper.rb', line 6

def code
  @code
end

Class Method Details

.from(node, code) ⇒ Object



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

def self.from(node, code)
  return node unless node.is_a?(RubyVM::AbstractSyntaxTree::Node) and !node.kind_of?(SimpleDelegator)

  new(node, code)
end

Instance Method Details

#childrenObject



43
44
45
# File 'lib/solargraph/parser/rubyvm/node_wrapper.rb', line 43

def children
  @children ||= __getobj__.children.map do |node| NodeWrapper.from(node, @code) end
end

#classObject



24
25
26
# File 'lib/solargraph/parser/rubyvm/node_wrapper.rb', line 24

def class
  __getobj__.class
end

#first_columnObject



29
30
31
32
33
34
# File 'lib/solargraph/parser/rubyvm/node_wrapper.rb', line 29

def first_column
  @first_column ||= begin
    line = @code[__getobj__.first_lineno - 1] || ""
    line.byteslice(0, __getobj__.first_column).length
  end
end

#is_a?(type) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/solargraph/parser/rubyvm/node_wrapper.rb', line 20

def is_a?(type)
  __getobj__.is_a?(type) || super.is_a?(type)
end

#last_columnObject



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

def last_column
  @last_column ||= begin
    line = @code[__getobj__.last_lineno - 1] || ""
    line.byteslice(0, __getobj__.last_column).length
  end
end