Class: Decode::Language::Ruby::Reference

Inherits:
Decode::Language::Reference show all
Defined in:
lib/decode/language/ruby/reference.rb

Overview

An Ruby-specific reference which can be resolved to zero or more definitions.

Instance Attribute Summary

Attributes inherited from Decode::Language::Reference

#identifier, #language

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Decode::Language::Reference

#absolute?, #best, #initialize, #inspect, #lexical_path, #path, #priority, #relative?, #to_s

Constructor Details

This class inherits a constructor from Decode::Language::Reference

Class Method Details

.append_const(node, path = []) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/decode/language/ruby/reference.rb', line 34

def self.append_const(node, path = [])
  parent, name = node.children
  
  if parent and parent.type != :cbase
    append_const(parent, path)
  end
  
  case node.type
  when :const
    if parent && parent.type != :cbase
      path << ['::', name]
    else
      path << [nil, name]
    end
  when :send
    path << ['#', name]
  when :cbase
    # Ignore.
  else
    raise ArgumentError, "Could not determine reference for #{node}!"
  end
  
  return path
end

.from_const(node, language) ⇒ Object



28
29
30
31
32
# File 'lib/decode/language/ruby/reference.rb', line 28

def self.from_const(node, language)
  lexical_path = append_const(node)
  
  return self.new(node.location.expression.source, language, lexical_path)
end

Instance Method Details

#split(text) ⇒ Object



59
60
61
# File 'lib/decode/language/ruby/reference.rb', line 59

def split(text)
  text.scan(/(::|\.|#|:)?([^:.#]+)/)
end