Class: Hash
Overview
:nodoc:
Instance Method Summary collapse
-
#symbolize_keys ⇒ Object
Only symbolize all keys, including all key in sub-hashes.
-
#to_struct ⇒ Object
Convert to Struct including all values that are Hash class.
Instance Method Details
#symbolize_keys ⇒ Object
Only symbolize all keys, including all key in sub-hashes.
31 32 33 34 35 36 37 |
# File 'lib/git/lighttp/extensions.rb', line 31 def symbolize_keys return clone if empty? each_with_object({}) do |(key, value), hash| hash[key.to_sym] = (value.is_a? Hash) ? value.symbolize_keys : value hash end end |
#to_struct ⇒ Object
Convert to Struct including all values that are Hash class.
40 41 42 43 44 45 46 47 |
# File 'lib/git/lighttp/extensions.rb', line 40 def to_struct attributes = keys.sort members = attributes.map(&:to_sym) Struct.new(*members).new(*attributes.map do |key| attribute = fetch key (attribute.is_a? Hash) ? attribute.to_struct : attribute end) unless empty? end |