Sha256: b9abe2af424cc0e1bba3e1f1ec5d9d95c6bae343848fdcdd3aa06689bd142bdc

Contents?: true

Size: 577 Bytes

Versions: 8

Compression:

Stored size: 577 Bytes

Contents

# frozen_string_literal: true

class HashWithIndifferentAccessCustom
  attr_reader :keys, :values, :attributes

  def initialize(hash = {})
    @attributes = {}
    hash.each { |key, val| self[key] = val }
    @keys = @attributes.keys
    @values = @attributes.values
  end

  def []=(key, value)
    @attributes[key.to_sym] = value
  end

  def [](key)
    @attributes[key.to_sym]
  end

  def self.[](*arr)
    new(Hash[*arr])
  end

  def delete(key)
    @attributes.delete(key)
    self.class.new(@attributes)
  end

  def to_json(*_args)
    @attributes.to_json
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
coredns-1.2.4 lib/helpers/hash_with_indifferent_access_custom.rb
coredns-1.2.3 lib/helpers/hash_with_indifferent_access_custom.rb
coredns-1.0.3 lib/helpers/hash_with_indifferent_access_custom.rb
coredns-1.2.1 lib/helpers/hash_with_indifferent_access_custom.rb
coredns-1.2.0 lib/helpers/hash_with_indifferent_access_custom.rb
coredns-1.0.2 lib/helpers/hash_with_indifferent_access_custom.rb
coredns-1.0.1 lib/helpers/hash_with_indifferent_access_custom.rb
coredns-1.0 lib/helpers/hash_with_indifferent_access_custom.rb