class Requirium::ConstInfo

Attributes

error[RW]
mod[RW]
nesting[RW]
sym[RW]
value[RW]

Public Class Methods

new(mod, sym, nesting) click to toggle source
# File lib/const_info.rb, line 5
def initialize(mod, sym, nesting)
  @mod, @sym, @nesting, @cond, @mutex = mod, sym, nesting, ConditionVariable.new, Mutex.new
end

Public Instance Methods

has_value?() click to toggle source
# File lib/const_info.rb, line 9
def has_value?
  !!(defined? @value)
end
internal_load() click to toggle source
# File lib/const_info.rb, line 13
def internal_load
  has, value = mod.send(:internal_load, self)
  @value = value if has
  nil
end
lookup_list() click to toggle source
# File lib/const_info.rb, line 19
def lookup_list
  return @nesting | @mod.ancestors if @nesting # always returns for mri

  # hacky fallback for jruby, rubinius, etc...

  # singleton classes don't have a name, but the base class is the first from the ancestors

  case
    # usual class
    when @mod.name
      split(@mod.name) | @mod.ancestors

    # singleton
    when @mod.ancestors.first != @mod
      mod = ObjectSpace.each_object(@mod).first
      split(mod.name) | mod.ancestors

    # anonymous class
    else
      mod.ancestors
  end

end
ready!() click to toggle source
# File lib/const_info.rb, line 43
def ready!
  @ready = true
  @mutex.synchronize { @cond.signal }
  nil
end
wait_ready() click to toggle source
# File lib/const_info.rb, line 49
def wait_ready
  @mutex.synchronize { until @ready; @cond.wait(@mutex) end }
  nil
end

Private Instance Methods

split(name) click to toggle source
# File lib/const_info.rb, line 56
def split(name)
  return [] unless name
  name.split('::').reduce([]) { |a, n| a << (a.last || Object).const_get(n) }.reverse!
end