Module: RbsShrine::Utils

Included in:
Shrine::Generator
Defined in:
lib/rbs_shrine/utils.rb

Instance Method Summary collapse

Instance Method Details

#format(rbs) ⇒ Object



8
9
10
11
12
13
# File 'lib/rbs_shrine/utils.rb', line 8

def format(rbs) #: String
  parsed = RBS::Parser.parse_signature(rbs)
  StringIO.new.tap do |out|
    RBS::Writer.new(out:).write(parsed[1] + parsed[2])
  end.string
end

#klass_to_names(klass) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rbs_shrine/utils.rb', line 16

def klass_to_names(klass) #: Array[RBS::TypeName]
  type_name = RBS::TypeName.parse("::#{klass.name}")

  names = [type_name] #: Array[RBS::TypeName]
  namespace = type_name.namespace
  until namespace.empty?
    names << namespace.to_type_name
    namespace = namespace.parent
  end
  names.reverse
end