Class: RbsMacros::MetaModule

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs_macros/meta_module.rb

Overview

Designates a module in a Ruby program being analyzed.

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#envObject (readonly)

Returns the value of attribute env.



6
7
8
# File 'lib/rbs_macros/meta_module.rb', line 6

def env
  @env
end

#is_classObject (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

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/rbs_macros/meta_module.rb', line 6

def name
  @name
end

#superclassObject (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 meta_const_get(name)
  @constants[name]
end

#meta_const_set(name, value) ⇒ Object



41
42
43
# File 'lib/rbs_macros/meta_module.rb', line 41

def meta_const_set(name, value)
  @constants[name] = value
end

#meta_constantsObject



49
50
51
# File 'lib/rbs_macros/meta_module.rb', line 49

def meta_constants
  @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_typeObject



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