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
26 27 28 |
# File 'lib/bogo/constants.rb', line 26 def const_val(name) self.class.const_get(name) end |
#constantize(string) ⇒ Object
Convert string to constant
12 13 14 15 16 17 18 19 20 |
# 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) ⇒ Class, Module
Provides namespace constant
34 35 36 37 38 39 40 41 42 |
# 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 |