123456789_123456789_123456789_123456789_123456789_

Module: RBS::Prototype::Runtime::Helpers

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: lib/rbs/prototype/runtime/helpers.rb

Instance Method Summary

Instance Method Details

#const_name(const) (private)

[ GitHub ]

  
# File 'lib/rbs/prototype/runtime/helpers.rb', line 19

def const_name(const)
  @module_name_method ||= Module.instance_method(:name)
  name = @module_name_method.bind(const).call
  return nil unless name

  begin
    deprecated, Warning[:deprecated] = Warning[:deprecated], false
    Object.const_get(name)
  rescue NameError
    # Should generate const name if anonymous or internal module (e.g. NameError::message)
    nil
  else
    name
  ensure
    Warning[:deprecated] = deprecated
  end
end

#const_name!(const) (private)

[ GitHub ]

  
# File 'lib/rbs/prototype/runtime/helpers.rb', line 15

def const_name!(const)
  const_name(const) or raise
end

#only_name(mod) (private)

Returns the exact name & not compactly declared name

[ GitHub ]

  
# File 'lib/rbs/prototype/runtime/helpers.rb', line 10

def only_name(mod)
  # No nil check because this method is invoked after checking if the module exists
  const_name!(mod).split(/::/).last or raise # (A::B::C) => C
end

#to_type_name(name, full_name: false) (private)

[ GitHub ]

  
# File 'lib/rbs/prototype/runtime/helpers.rb', line 37

def to_type_name(name, full_name: false)
  *prefix, last = name.split(/::/)

  last or raise

  if full_name
    if prefix.empty?
      TypeName.new(name: last.to_sym, namespace: Namespace.empty)
    else
      TypeName.new(name: last.to_sym, namespace: Namespace.parse(prefix.join("::")))
    end
  else
    TypeName.new(name: last.to_sym, namespace: Namespace.empty)
  end
end

#untyped (private)

[ GitHub ]

  
# File 'lib/rbs/prototype/runtime/helpers.rb', line 53

def untyped
  @untyped ||= Types::Bases::Any.new(location: nil)
end