Class: Myco::ConstantReference

Inherits:
Object
  • Object
show all
Defined in:
lib/myco/bootstrap/find_constant.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, scope) ⇒ ConstantReference

Returns a new instance of ConstantReference.



91
92
93
94
# File 'lib/myco/bootstrap/find_constant.rb', line 91

def initialize name, scope
  @name  = name
  @scope = scope
end

Class Attribute Details

.verboseObject

Returns the value of attribute verbose.



85
86
87
# File 'lib/myco/bootstrap/find_constant.rb', line 85

def verbose
  @verbose
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



88
89
90
# File 'lib/myco/bootstrap/find_constant.rb', line 88

def name
  @name
end

#scopeObject (readonly)

Returns the value of attribute scope.



89
90
91
# File 'lib/myco/bootstrap/find_constant.rb', line 89

def scope
  @scope
end

Instance Method Details

#find_constant_bucket_in_module(mod, name) ⇒ Object



118
119
120
121
122
123
124
125
126
127
# File 'lib/myco/bootstrap/find_constant.rb', line 118

def find_constant_bucket_in_module mod, name
  current = mod
  while current and Rubinius::Type.object_kind_of? current, Module
    # p current if Myco::ConstantReference.verbose
    return bucket if bucket = current.constant_table.lookup(name)
    current = current.direct_superclass
  end
  
  return nil
end

#find_valueObject



108
109
110
111
112
113
114
115
116
# File 'lib/myco/bootstrap/find_constant.rb', line 108

def find_value
  bucket = find_constant_bucket_in_module(scope.module, name)
  bucket ? bucket.constant : (
    parent = scope.myco_parent
    parent ? parent.get_myco_constant_ref(name).value : (
      Rubinius::Type.const_get(::Myco, name)
    )
  )
end

#valueObject



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/myco/bootstrap/find_constant.rb', line 96

def value
  serial = @serial
  new_serial = Rubinius.global_serial
  
  if serial && serial >= new_serial
    @value
  else
    @serial = new_serial
    @value = find_value
  end
end