Class: Decode::Symbol
- Inherits:
-
Object
- Object
- Decode::Symbol
- Defined in:
- lib/decode/symbol.rb
Overview
A named element which represents some significant element of some kind in a computer program.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#kind ⇒ Object
readonly
The kind of symbol.
-
#language ⇒ Object
readonly
The language the symbol is defined within.
-
#name ⇒ Object
readonly
The symbol name.
-
#parent ⇒ Object
readonly
The parent symbol, defining lexical scope.
Instance Method Summary collapse
-
#initialize(kind, name, parent: nil, language: parent.language) ⇒ Symbol
constructor
Initialize the symbol.
- #inspect ⇒ Object
-
#key ⇒ Key
A symbol-specific key which represents the lexical scope.
-
#lexical_path ⇒ Object
The lexical path, only taking into account the symbol names.
- #path ⇒ Array
-
#qualified_name ⇒ Object
The qualified name is an absolute name which includes any and all namespacing.
Constructor Details
#initialize(kind, name, parent: nil, language: parent.language) ⇒ Symbol
Initialize the symbol.
34 35 36 37 38 39 40 41 42 |
# File 'lib/decode/symbol.rb', line 34 def initialize(kind, name, parent: nil, language: parent.language) @kind = kind @name = name @parent = parent @language = language @path = nil @qualified_name = nil end |
Instance Attribute Details
#kind ⇒ Object (readonly)
The kind of symbol. e.g. ‘:module`.
56 57 58 |
# File 'lib/decode/symbol.rb', line 56 def kind @kind end |
#language ⇒ Object (readonly)
The language the symbol is defined within.
66 67 68 |
# File 'lib/decode/symbol.rb', line 66 def language @language end |
#name ⇒ Object (readonly)
The symbol name. e.g. ‘:Decode`.
60 61 62 |
# File 'lib/decode/symbol.rb', line 60 def name @name end |
#parent ⇒ Object (readonly)
The parent symbol, defining lexical scope.
63 64 65 |
# File 'lib/decode/symbol.rb', line 63 def parent @parent end |
Instance Method Details
#inspect ⇒ Object
50 51 52 |
# File 'lib/decode/symbol.rb', line 50 def inspect "\#<#{self.class} #{@kind} #{qualified_name}>" end |
#key ⇒ Key
A symbol-specific key which represents the lexical scope.
46 47 48 |
# File 'lib/decode/symbol.rb', line 46 def key Key.new(@kind, @name) end |
#lexical_path ⇒ Object
The lexical path, only taking into account the symbol names.
86 87 88 |
# File 'lib/decode/symbol.rb', line 86 def lexical_path self.path.map(&:name) end |
#path ⇒ Array
75 76 77 78 79 80 81 82 83 |
# File 'lib/decode/symbol.rb', line 75 def path if @path @path elsif @parent @path = [*@parent.path, self.key] else @path = [self.key] end end |
#qualified_name ⇒ Object
The qualified name is an absolute name which includes any and all namespacing.
69 70 71 |
# File 'lib/decode/symbol.rb', line 69 def qualified_name @qualified_name ||= @language.join(self.path).freeze end |