module Opto::Extension::HashStringOrSymbolKey

Refines Hash so that [] and delete work with :symbol or 'string' keys

Public Instance Methods

[](key) click to toggle source
Calls superclass method
# File lib/opto/extensions/hash_string_or_symbol_key.rb, line 6
def [](key)
  return super(nil) if key.nil?

  [key, key.to_s, key.to_sym].each do |k|
    val = super(k)
    return val unless val.nil?
  end
  super(key)
end
delete(key) click to toggle source
Calls superclass method
# File lib/opto/extensions/hash_string_or_symbol_key.rb, line 24
def delete(key)
  return nil if key.nil?
  [key, key.to_s, key.to_sym].each do |k|
    val = super(k)
    return val unless val.nil?
  end
  nil
end
has_key?(key) click to toggle source
Calls superclass method
# File lib/opto/extensions/hash_string_or_symbol_key.rb, line 16
def has_key?(key)
  return super(nil) if key.nil?
  [key, key.to_s, key.to_sym].each do |k|
    return true if super(k)
  end
  false
end