Sha256: f50ff226a598e0ef38bdd4cabfd4e544d28613f3c32f79587bb85fb96eb21958

Contents?: true

Size: 697 Bytes

Versions: 5

Compression:

Stored size: 697 Bytes

Contents

class SymbolHash < Hash
  def initialize(symbolize_value = true)
    @symbolize_value = symbolize_value
  end
  
  def self.[](*hsh)
    obj = new;
    if hsh.size == 1 && hsh.first.is_a?(Hash)
      hsh.first.each {|k,v| obj[k] = v }
    else
      0.step(hsh.size, 2) {|n| obj[hsh[n]] = hsh[n+1] }
    end
    obj
  end
  
  def []=(key, value) 
    super(key.to_sym, value.instance_of?(String) && @symbolize_value ? value.to_sym : value) 
  end
  def [](key) super(key.to_sym) end
  def delete(key) super(key.to_sym) end
  def has_key?(key) super(key.to_sym) end
  def update(hsh) hsh.each {|k,v| self[k] = v }; self end
  alias_method :merge!, :update
  def merge(hsh) dup.merge!(hsh) end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
yard-0.2.3.5 lib/yard/core_ext/symbol_hash.rb
yard-0.2.3.4 lib/yard/core_ext/symbol_hash.rb
yard-0.2.3.2 lib/yard/core_ext/symbol_hash.rb
yard-0.2.3.3 lib/yard/core_ext/symbol_hash.rb
yard-0.2.3 lib/yard/core_ext/symbol_hash.rb