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 symbols.
Constant Summary collapse
- KIND =
{ ':' => :def, '.' => :defs, }.freeze
- METHOD =
/\A(?<scope>.*?)?(?<kind>:|\.)(?<name>.+?)\z/
Instance Method Summary collapse
-
#absolute? ⇒ Boolean
Whether the reference starts at the base of the lexical tree.
-
#initialize(value) ⇒ Reference
constructor
Initialize the reference.
-
#kind ⇒ Object
The kind of symbol to match.
-
#path ⇒ Array(String)
The lexical path of the reference.
Constructor Details
#initialize(value) ⇒ Reference
Initialize the reference.
33 34 35 36 37 38 |
# File 'lib/decode/language/ruby/reference.rb', line 33 def initialize(value) @value = value @path = nil @kind = nil end |
Instance Method Details
#absolute? ⇒ Boolean
Whether the reference starts at the base of the lexical tree.
41 42 43 |
# File 'lib/decode/language/ruby/reference.rb', line 41 def absolute? @value.start_with?('::') end |
#kind ⇒ Object
The kind of symbol to match.
75 76 77 78 79 |
# File 'lib/decode/language/ruby/reference.rb', line 75 def kind self.path return @kind end |
#path ⇒ Array(String)
The lexical path of the reference.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/decode/language/ruby/reference.rb', line 49 def path if @path.nil? @path = @value.split(/::/) if last = @path.pop if match = last.match(METHOD) @kind = KIND[match[:kind]] if scope = match[:scope] @path << scope end @path << match[:name] else @path << last end end @path = @path.map(&:to_sym) @path.freeze end return @path end |