Module: Bogo::Constants
- Included in:
- Utility
- Defined in:
- lib/bogo/constants.rb
Overview
Constant helper
Instance Method Summary collapse
-
#const_val(name) ⇒ Object
Return constant value localized to calling instance class.
-
#constantize(string) ⇒ Object
Convert string to constant.
-
#namespace(inst = self) ⇒ Class, Module
Provides namespace constant.
Instance Method Details
#const_val(name) ⇒ Object
Return constant value localized to calling instance class
22 23 24 |
# File 'lib/bogo/constants.rb', line 22 def const_val(name) self.class.const_get(name) end |
#constantize(string) ⇒ Object
Convert string to constant
8 9 10 11 12 13 14 15 16 |
# File 'lib/bogo/constants.rb', line 8 def constantize(string) string.split('::').inject(ObjectSpace) do |memo, key| begin memo.const_get(key) rescue NameError break end end end |
#namespace(inst = self) ⇒ Class, Module
Provides namespace constant
30 31 32 33 34 35 36 37 38 |
# File 'lib/bogo/constants.rb', line 30 def namespace(inst = self) klass = inst.class.name.split('::') klass.pop if(klass.empty?) ObjectSpace else constantize(klass.join('::')) end end |