Class: Decode::Language::Ruby::Reference
- Inherits:
-
Decode::Language::Reference
- Object
- Decode::Language::Reference
- Decode::Language::Ruby::Reference
- 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
#The identifier part of the reference., #The language associated with this reference., #identifier, #language
Class Method Summary collapse
-
.append_const(node, path = []) ⇒ Object
Append a constant node to the path.
-
.from_const(node, language) ⇒ Object
Create a reference from a constant node.
Instance Method Summary collapse
-
#split(text) ⇒ Object
Split a Ruby identifier into prefix and name components.
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
Append a constant node to the path.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/decode/language/ruby/reference.rb', line 27 def self.append_const(node, path = []) case node.type when :constant_read_node path << [nil, node.name.to_s] when :constant_path_node if node.parent append_const(node.parent, path) path << ["::", node.name.to_s] else path << [nil, node.name.to_s] end when :call_node # For call nodes like Tuple(...), treat them as constant references if node.receiver.nil? path << [nil, node.name.to_s] else append_const(node.receiver, path) path << [".", node.name.to_s] end else raise ArgumentError, "Could not determine reference for #{node.type}!" end return path end |
.from_const(node, language) ⇒ Object
Create a reference from a constant node.
17 18 19 20 21 |
# File 'lib/decode/language/ruby/reference.rb', line 17 def self.from_const(node, language) lexical_path = append_const(node) return self.new(node.location.slice, language, lexical_path) end |
Instance Method Details
#split(text) ⇒ Object
Split a Ruby identifier into prefix and name components.
56 57 58 |
# File 'lib/decode/language/ruby/reference.rb', line 56 def split(text) text.scan(/(::|\.|#|:)?([^:.#]+)/) end |