Module: RBS::Prototype::Runtime::Helpers
- Included in:
- RBS::Prototype::Runtime, ValueObjectBase
- Defined in:
- lib/rbs/prototype/runtime/helpers.rb,
sig/prototype/runtime.rbs
Instance Method Summary collapse
- #const_name(const) ⇒ String?
- #const_name!(const) ⇒ String
-
#only_name(mod) ⇒ String
Returns the exact name & not compactly declared name.
- #to_type_name(name, full_name: false) ⇒ TypeName
- #untyped ⇒ Types::Bases::Any
Instance Method Details
#const_name(const) ⇒ String?
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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) ⇒ String
15 16 17 |
# File 'lib/rbs/prototype/runtime/helpers.rb', line 15 def const_name!(const) const_name(const) or raise end |
#only_name(mod) ⇒ String
Returns the exact name & not compactly declared name
10 11 12 13 |
# 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) ⇒ TypeName
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# 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 ⇒ Types::Bases::Any
53 54 55 |
# File 'lib/rbs/prototype/runtime/helpers.rb', line 53 def untyped @untyped ||= Types::Bases::Any.new(location: nil) end |