Module: Mondo::Utils
Instance Method Summary collapse
-
#camelize(str) ⇒ Object
String Helpers.
-
#symbolize_keys(hash) ⇒ Object
Hash Helpers.
- #symbolize_keys!(hash) ⇒ Object
- #underscore(str) ⇒ Object
Instance Method Details
#camelize(str) ⇒ Object
String Helpers
8 9 10 |
# File 'lib/mondo/utils.rb', line 8 def camelize(str) str.split('_').map(&:capitalize).join end |
#symbolize_keys(hash) ⇒ Object
Hash Helpers
17 18 19 |
# File 'lib/mondo/utils.rb', line 17 def symbolize_keys(hash) symbolize_keys! hash.dup end |
#symbolize_keys!(hash) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/mondo/utils.rb', line 21 def symbolize_keys!(hash) hash.keys.each do |key| sym_key = key.to_s.to_sym rescue key hash[sym_key] = hash.delete(key) unless hash.key?(sym_key) end hash end |
#underscore(str) ⇒ Object
12 13 14 |
# File 'lib/mondo/utils.rb', line 12 def underscore(str) str.gsub(/(.)([A-Z])/) { "#{$1}_#{$2.downcase}" }.downcase end |