Module: Radius::Util
- Defined in:
- lib/radius/util.rb
Overview
:nodoc:
Class Method Summary collapse
- .camelize(underscored_string) ⇒ Object
- .constantize(camelized_string) ⇒ Object
- .impartial_hash_delete(hash, key) ⇒ Object
- .symbolize_keys(hash) ⇒ Object
Class Method Details
.camelize(underscored_string) ⇒ Object
24 25 26 27 28 |
# File 'lib/radius/util.rb', line 24 def self.camelize(underscored_string) string = '' underscored_string.split('_').each { |part| string << part.capitalize } string end |
.constantize(camelized_string) ⇒ Object
19 20 21 22 |
# File 'lib/radius/util.rb', line 19 def self.constantize(camelized_string) raise "invalid constant name `#{camelized_string}'" unless camelized_string.split('::').all? { |part| part =~ /^[A-Za-z]+$/ } Object.module_eval(camelized_string) end |
.impartial_hash_delete(hash, key) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/radius/util.rb', line 11 def self.impartial_hash_delete(hash, key) string = key.to_s symbol = string.intern value1 = hash.delete(symbol) value2 = hash.delete(string) value1 || value2 end |
.symbolize_keys(hash) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/radius/util.rb', line 3 def self.symbolize_keys(hash) new_hash = {} hash.keys.each do |k| new_hash[k.to_s.intern] = hash[k] end new_hash end |