Class: RbsMacros::MetaModule
- Inherits:
-
Object
- Object
- RbsMacros::MetaModule
- Defined in:
- lib/rbs_macros/meta_module.rb
Overview
Designates a module in a Ruby program being analyzed.
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#is_class ⇒ Object
readonly
Returns the value of attribute is_class.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#superclass ⇒ Object
readonly
Returns the value of attribute superclass.
Instance Method Summary collapse
- #class! ⇒ Object
- #define_module(name) ⇒ Object
-
#initialize(env, name, is_class: nil, superclass: nil) ⇒ MetaModule
constructor
A new instance of MetaModule.
- #meta_const_get(name) ⇒ Object
- #meta_const_set(name, value) ⇒ Object
- #meta_constants ⇒ Object
- #module! ⇒ Object
- #rbs_type ⇒ Object
Constructor Details
#initialize(env, name, is_class: nil, superclass: nil) ⇒ MetaModule
Returns a new instance of MetaModule.
8 9 10 11 12 13 14 |
# File 'lib/rbs_macros/meta_module.rb', line 8 def initialize(env, name, is_class: nil, superclass: nil) @env = env @name = name @is_class = is_class @superclass = superclass @constants = {} end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
6 7 8 |
# File 'lib/rbs_macros/meta_module.rb', line 6 def env @env end |
#is_class ⇒ Object (readonly)
Returns the value of attribute is_class.
6 7 8 |
# File 'lib/rbs_macros/meta_module.rb', line 6 def is_class @is_class end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/rbs_macros/meta_module.rb', line 6 def name @name end |
#superclass ⇒ Object (readonly)
Returns the value of attribute superclass.
6 7 8 |
# File 'lib/rbs_macros/meta_module.rb', line 6 def superclass @superclass end |
Instance Method Details
#class! ⇒ Object
29 30 31 |
# File 'lib/rbs_macros/meta_module.rb', line 29 def class! @is_class = true if @is_class.nil? end |
#define_module(name) ⇒ Object
37 38 39 |
# File 'lib/rbs_macros/meta_module.rb', line 37 def define_module(name) @constants[name] ||= MetaModule.new(@env, child_module_name(name.to_s)) end |
#meta_const_get(name) ⇒ Object
45 46 47 |
# File 'lib/rbs_macros/meta_module.rb', line 45 def (name) @constants[name] end |
#meta_const_set(name, value) ⇒ Object
41 42 43 |
# File 'lib/rbs_macros/meta_module.rb', line 41 def (name, value) @constants[name] = value end |
#meta_constants ⇒ Object
49 50 51 |
# File 'lib/rbs_macros/meta_module.rb', line 49 def @constants.keys end |
#module! ⇒ Object
33 34 35 |
# File 'lib/rbs_macros/meta_module.rb', line 33 def module! @is_class = false if @is_class.nil? end |
#rbs_type ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/rbs_macros/meta_module.rb', line 16 def rbs_type return @rbs_type if defined?(@rbs_type) *ns, name = (@name || raise("Anonymous module given")).split("::") @rbs_type = RBS::TypeName.new( name: (name || raise("Anonymous module gien")).to_sym, namespace: RBS::Namespace.new( path: ns.map(&:to_sym), absolute: true ) ) end |