Class: Hash

Inherits:
Object show all
Defined in:
lib/git/lighttp/extensions.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#symbolize_keysObject

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_structObject

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