Sha256: b91196f7a0ae62ebefe098209bdacb03d43501e7f5337cad8cc39fdbc559b5a6
Contents?: true
Size: 449 Bytes
Versions: 1
Compression:
Stored size: 449 Bytes
Contents
# Cribbed from http://andreapavoni.com/blog/2013/4/create-recursive-openstruct-from-a-ruby-hash/ require 'ostruct' class DeepStruct < OpenStruct def initialize(hash = nil) @table = {} @hash_table = {} return unless hash hash.each do |k, v| k = k.to_s @table[k.to_sym] = (v.is_a?(Hash) ? self.class.new(v) : v) @hash_table[k] = v new_ostruct_member(k) end end def to_h @hash_table end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rails-service-0.1.0 | lib/rails/service/core_ext/deep_struct.rb |