Module: Kernel

Defined in:
lib/mspec/helpers/const_lookup.rb

Instance Method Summary collapse

Instance Method Details

#const_lookup(c) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
# File 'lib/mspec/helpers/const_lookup.rb', line 4

def const_lookup(c)
  extra_arg = SpecVersion.new(RUBY_VERSION) >= "1.9"

  names = c.split '::'
  names.shift if names.first.empty?

  names.inject(Object) do |m, n|
    defined = extra_arg ? m.const_defined?(n, false) : m.const_defined?(n)
    defined ? m.const_get(n) : m.const_missing(n)
  end
end