Class: Module

Inherits:
Object show all
Includes:
Moon::Abstract
Defined in:
lib/moon/packages/std/core_ext/module.rb,
lib/moon/packages/std/core_ext/module/const_get.rb,
lib/moon/packages/std/mixins/abstract/core_ext/module.rb

Instance Method Summary collapse

Methods included from Moon::Abstract

#abstract, #abstract_attr_accessor, #abstract_attr_reader, #abstract_attr_writer

Instance Method Details

#__const_get__Object


2
# File 'lib/moon/packages/std/core_ext/module/const_get.rb', line 2

alias :__const_get__ :const_get

#const_get(path) ⇒ Module

const_get resolves namespaces and top level constants!

Parameters:

Returns:


8
9
10
11
12
13
14
15
16
# File 'lib/moon/packages/std/core_ext/module/const_get.rb', line 8

def const_get(path)
  top = self
  paths = path.to_s.split("::")
  if path.to_s.start_with?("::")
    top = Object
    paths.shift
  end
  paths.reduce(top) { |klass, name| klass.__const_get__(name) }
end

#enum_const(*symbols) ⇒ Object #enum_const(options) ⇒ Object

Defines a number of constants given a Hash or set of Symbols. When given a Hash, the keys are treated as the const_name. When given a Symbol, the Symbol is treated const_name and the value is index of the symbol in the symbols.

Overloads:


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/moon/packages/std/core_ext/module.rb', line 11

def enum_const(*args)
  if args.first.is_a?(Hash)
    args.first.each do |key, i|
      const_set(key, i)
    end
  else
    args.each_with_index do |s, i|
      const_set(s, i)
    end
  end
end