lib/rbs/namespace.rb in rbs-0.11.0 vs lib/rbs/namespace.rb in rbs-0.12.0

- old
+ new

@@ -61,11 +61,13 @@ def hash self.class.hash ^ path.hash ^ absolute?.hash end def split - [parent, path.last] + last = path.last or return + parent = self.parent + [parent, last] end def to_s if empty? absolute? ? "::" : "" @@ -75,10 +77,14 @@ end end def to_type_name parent, name = split + + raise unless name + raise unless parent + TypeName.new(name: name, namespace: parent) end def self.parse(string) if string.start_with?("::") @@ -86,24 +92,29 @@ else new(path: string.split("::").map(&:to_sym), absolute: false) end end - def ascend if block_given? current = self until current.empty? yield current - current = current.parent + current = _ = current.parent end yield current self else enum_for(:ascend) end end + end +end + +module Kernel + def Namespace(name) + RBS::Namespace.parse(name) end end