Class: RBS::Namespace
| Relationships & Source Files | |
| Inherits: | Object |
| Defined in: | lib/rbs/namespace.rb |
Constant Summary
-
INTERN_LEAF =
# File 'lib/rbs/namespace.rb', line 18Module.new
Class Method Summary
-
.[](path, absolute)
Returns a canonical
Namespaceinstance for the given #path /absolutepair. - .empty
- .new(path:, absolute:) ⇒ Namespace constructor
- .parse(string)
- .root
Instance Attribute Summary
- #absolute? ⇒ Boolean readonly
- #empty? ⇒ Boolean readonly
- #path readonly
- #relative? ⇒ Boolean readonly
Instance Method Summary
- #+(other)
- #==(other) (also: #eql?)
- #absolute!
- #append(component)
- #ascend
-
#eql?(other)
Alias for #==.
- #hash
- #parent
- #relative!
- #split
- #to_s
- #to_type_name
Constructor Details
.new(path:, absolute:) ⇒ Namespace
# File 'lib/rbs/namespace.rb', line 7
def initialize(path:, absolute:) @path = path @absolute = absolute ? true : false end
Class Method Details
.[](path, absolute)
Returns a canonical Namespace instance for the given #path /
absolute pair. Repeated calls with structurally equal arguments
return the same object, so callers can rely on equal? for fast
equality. The path Array is duplicated and frozen on insert.
# File 'lib/rbs/namespace.rb', line 24
def self.[](path, absolute) absolute = absolute ? true : false # Lock-free fast path. node = absolute ? @intern_trie_absolute : @intern_trie_relative path.each do |sym| node = node[sym] break unless node end if node && (cached = node[INTERN_LEAF]) return cached end @intern_mutex.synchronize do node = absolute ? @intern_trie_absolute : @intern_trie_relative path.each { |sym| node = (node[sym] ||= {}) } node[INTERN_LEAF] ||= begin frozen_path = path.frozen? ? path : path.dup.freeze new(path: frozen_path, absolute: absolute) end end end
.empty
[ GitHub ]# File 'lib/rbs/namespace.rb', line 47
def self.empty @empty ||= self[[], false] end
.parse(string)
[ GitHub ].root
[ GitHub ]# File 'lib/rbs/namespace.rb', line 51
def self.root @root ||= self[[], true] end
Instance Attribute Details
#absolute? ⇒ Boolean (readonly)
[ GitHub ]
# File 'lib/rbs/namespace.rb', line 74
def absolute? @absolute end
#empty? ⇒ Boolean (readonly)
[ GitHub ]
# File 'lib/rbs/namespace.rb', line 90
def empty? path.empty? end
#path (readonly)
[ GitHub ]# File 'lib/rbs/namespace.rb', line 5
attr_reader :path
#relative? ⇒ Boolean (readonly)
[ GitHub ]
# File 'lib/rbs/namespace.rb', line 78
def relative? !absolute? end
Instance Method Details
#+(other)
[ GitHub ]#==(other) Also known as: #eql?
[ GitHub ]#absolute!
[ GitHub ]# File 'lib/rbs/namespace.rb', line 82
def absolute! Namespace[path, true] end
#append(component)
[ GitHub ]#ascend
[ GitHub ]#eql?(other)
Alias for #==.
# File 'lib/rbs/namespace.rb', line 99
alias eql? ==
#hash
[ GitHub ]#parent
[ GitHub ]#relative!
[ GitHub ]# File 'lib/rbs/namespace.rb', line 86
def relative! Namespace[path, false] end