module Bogo::Constants

Constant helper

Public Instance Methods

const_val(name) click to toggle source

Return constant value localized to calling instance class

@param name [String, Symbol] constant name @return [Object]

# File lib/bogo/constants.rb, line 26
def const_val(name)
  self.class.const_get(name)
end
constantize(string) click to toggle source

Convert string to constant

@param string [String] full constant name @return [Object]

# File lib/bogo/constants.rb, line 12
def constantize(string)
  string.split('::').inject(ObjectSpace) do |memo, key|
    begin
      memo.const_get(key)
    rescue NameError
      break
    end
  end
end
namespace(inst = self) click to toggle source

Provides namespace constant

@param inst [Object] @return [Class, Module]

# File lib/bogo/constants.rb, line 34
def namespace(inst = self)
  klass = inst.class.name.split('::')
  klass.pop
  if(klass.empty?)
    ObjectSpace
  else
    constantize(klass.join('::'))
  end
end