Module: Rbeapi::Utils
- Defined in:
- lib/rbeapi/utils.rb
Overview
Utils module
Class Method Summary collapse
-
.class_from_string(name) ⇒ Object
Returns a class object from a string capable of being instatiated.
-
.transform_keys_to_symbols(value) ⇒ Hash
Iterates through a hash structure and converts all of the keys to symbols.
Class Method Details
.class_from_string(name) ⇒ Object
Returns a class object from a string capable of being instatiated
63 64 65 66 67 |
# File 'lib/rbeapi/utils.rb', line 63 def self.class_from_string(name) name.split('::').inject(Object) do |mod, cls| mod.const_get(cls) end end |
.transform_keys_to_symbols(value) ⇒ Hash
Iterates through a hash structure and converts all of the keys to symbols.
48 49 50 51 52 53 54 55 |
# File 'lib/rbeapi/utils.rb', line 48 def self.transform_keys_to_symbols(value) return value if not value.kind_of?(Hash) hash = value.inject({}) do |hsh, (k,v)| hsh[k.to_sym] = self.transform_keys_to_symbols(v) hsh end hash end |