Sha256: f03980cadc7169a7c523a16a1c983662e5368d4fc2389901361b515112346801

Contents?: true

Size: 563 Bytes

Versions: 3

Compression:

Stored size: 563 Bytes

Contents

module TreeConfig 
  class DeepStruct < OpenStruct
    def initialize(hash=nil)
      @table = {}
      @hash_table = {}

      if hash
        hash.each do |k,v|
          raise KeyIsFixNum if k.instance_of?(Fixnum)
          @table[k.to_sym] = (v.is_a?(Hash) ? self.class.new(v) : v)
          @hash_table[k.to_sym] = v
          new_ostruct_member(k)
        end
      end
    end

    def to_h
      @hash_table
    end

    def empty?
      self.hash == 0
    end

    def size
      sum = 0
      self.each_pair { |p| sum += 1 }
      sum
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
tree_config-0.0.3 lib/tree_config/vendor/deep_struct.rb
tree_config-0.0.2 lib/tree_config/vendor/deep_struct.rb
tree_config-0.0.1 lib/tree_config/vendor/deep_struct.rb