Class: Decode::Symbol

Inherits:
Object
  • Object
show all
Defined in:
lib/decode/symbol.rb

Direct Known Subclasses

Definition

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(kind, name, parent: nil, language: parent.language) ⇒ Symbol

Returns a new instance of Symbol.



27
28
29
30
31
32
33
34
35
# File 'lib/decode/symbol.rb', line 27

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

#kindObject (readonly)

Returns the value of attribute kind.



45
46
47
# File 'lib/decode/symbol.rb', line 45

def kind
  @kind
end

#languageObject (readonly)

Returns the value of attribute language.



48
49
50
# File 'lib/decode/symbol.rb', line 48

def language
  @language
end

#nameObject (readonly)

Returns the value of attribute name.



46
47
48
# File 'lib/decode/symbol.rb', line 46

def name
  @name
end

#parentObject (readonly)

Returns the value of attribute parent.



47
48
49
# File 'lib/decode/symbol.rb', line 47

def parent
  @parent
end

Instance Method Details

#inspectObject



41
42
43
# File 'lib/decode/symbol.rb', line 41

def inspect
	"\#<#{self.class} #{@kind} #{qualified_name}>"
end

#keyObject



37
38
39
# File 'lib/decode/symbol.rb', line 37

def key
	Key.new(@kind, @name)
end

#lexical_pathObject



64
65
66
# File 'lib/decode/symbol.rb', line 64

def lexical_path
	self.path.map(&:name)
end

#pathObject



54
55
56
57
58
59
60
61
62
# File 'lib/decode/symbol.rb', line 54

def path
	if @path
		@path
	elsif @parent
		@path = [*@parent.path, self.key]
	else
		@path = [self.key]
	end
end

#qualified_nameObject



50
51
52
# File 'lib/decode/symbol.rb', line 50

def qualified_name
	@qualified_name ||= @language.join(self.path).freeze
end