Sha256: 1ad6aeb02704c140e69bb2e17711d47079f76e824dbb314f09f196e7c5911ad1

Contents?: true

Size: 509 Bytes

Versions: 21

Compression:

Stored size: 509 Bytes

Contents

# frozen_string_literal: true

module Isolator
  # Hash with key accessors
  class SimpleHashie < Hash
    def method_missing(key, *args, &block)
      key_str = key.to_s

      if key_str.end_with?("=")
        self[key_str.tr("=")] = args.first
      else
        fetch(key_str) { super }
      end
    end

    def respond_to_missing?(key)
      key_str = key.to_s
      if key_str.end_with?("=")
        key?(key_str.tr("=")) || super
      else
        key?(key_str) || super
      end
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
isolator-0.1.0.pre lib/isolator/simple_hashie.rb