Class: Decode::Language::Ruby::Reference
- Inherits:
-
Object
- Object
- 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 collapse
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Instance Method Summary collapse
-
#absolute? ⇒ Boolean
Whether the reference starts at the base of the lexical tree.
- #best(definitions) ⇒ Object
-
#initialize(text) ⇒ Reference
constructor
Initialize the reference.
- #language ⇒ Object
- #lexical_path ⇒ Object
-
#path ⇒ Array(String)
The lexical path of the reference.
Constructor Details
#initialize(text) ⇒ Reference
Initialize the reference.
28 29 30 31 32 33 |
# File 'lib/decode/language/ruby/reference.rb', line 28 def initialize(text) @text = text @lexical_path = nil @path = nil end |
Instance Attribute Details
#text ⇒ Object (readonly)
Returns the value of attribute text.
39 40 41 |
# File 'lib/decode/language/ruby/reference.rb', line 39 def text @text end |
Instance Method Details
#absolute? ⇒ Boolean
Whether the reference starts at the base of the lexical tree.
42 43 44 |
# File 'lib/decode/language/ruby/reference.rb', line 42 def absolute? @text.start_with?('::') end |
#best(definitions) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/decode/language/ruby/reference.rb', line 50 def best(definitions) prefix, name = lexical_path.last definitions.select do |definition| prefix.nil? || definition.start_with?(prefix) end end |
#language ⇒ Object
35 36 37 |
# File 'lib/decode/language/ruby/reference.rb', line 35 def language Ruby end |
#lexical_path ⇒ Object
46 47 48 |
# File 'lib/decode/language/ruby/reference.rb', line 46 def lexical_path @lexical_path ||= @text.scan(/(::|\.|#|:)?([^:.#]+)/) end |
#path ⇒ Array(String)
The lexical path of the reference.
60 61 62 |
# File 'lib/decode/language/ruby/reference.rb', line 60 def path @path ||= self.lexical_path.map{|_, name| name.to_sym} end |