Sha256: d7ada2d98e1fd77da37e8bdc64ff76a30fd3c0df7216da9355008012bb4af229
Contents?: true
Size: 762 Bytes
Versions: 4
Compression:
Stored size: 762 Bytes
Contents
# frozen_string_literal: true module Appydave module Tools # Hash with indifferent access class IndifferentAccessHash < Hash def initialize(initial_hash = {}) super() update(initial_hash) end def [](key) super(convert_key(key)) end def []=(key, value) super(convert_key(key), value) end def fetch(key, *args) super(convert_key(key), *args) end def delete(key) super(convert_key(key)) end private def convert_key(key) key.is_a?(Symbol) ? key.to_s : key end def update(initial_hash) initial_hash.each do |key, value| self[convert_key(key)] = value end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems