Class: Hash

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

Instance Method Summary collapse

Instance Method Details

#to_structObject

Convert to Struct including all values that are Hash class.



3
4
5
6
7
8
9
# File 'lib/git/webby/extensions.rb', line 3

def to_struct
  keys    = self.keys.sort
  members = keys.map(&:to_sym)
  Struct.new(*members).new(*keys.map do |key|
    (self[key].kind_of? Hash) ?  self[key].to_struct : self[key]
  end) unless self.empty?
end