Method: Bj::Util::ModuleMethods#constant_get

Defined in:
lib/bj/util.rb

#constant_get(const, &block) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/bj/util.rb', line 4

def constant_get const, &block
  begin
    ancestors = const.split(%r/::/)
    parent = Object
    while((child = ancestors.shift))
      klass = parent.const_get child
      parent = klass
    end
    klass
  rescue
    block ? block.call : raise
  end
end