Class: Goat::IndifferentHash
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Hash
Class Method Details
.from_hash(hash) ⇒ Object
499 500 501 502 503 504 505 |
# File 'lib/goat.rb', line 499 def self.from_hash(hash) ih = self.new hash.each do |k, v| ih[k] = v end ih end |
Instance Method Details
#[](k) ⇒ Object
507 508 509 510 511 512 513 514 515 516 517 |
# File 'lib/goat.rb', line 507 def [](k) if k.kind_of?(Symbol) k_sym = k k_str = k.to_s raise 'Invalid hash' if self.include?(k_sym) && self.include?(k_str) self.include?(k_str) ? self.fetch(k_str) : self.fetch(k_sym, nil) else super(k) end end |