Class: IndifferentHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/indifferent_hash.rb

Overview

Contains IndifferentHash, which can be deferenced by strings or symbols. It doesn’t care, it’s laid back.

Authors

Copyright © 2007 Laika, Inc.

This code released under the terms of the BSD license.

Version

$Id: indifferent_hash.rb 274 2007-07-25 21:06:42Z bbleything $

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/indifferent_hash.rb', line 22

def []( key )
	candidate = self.fetch( key ) rescue false
	return candidate if candidate

	[ :to_s, :intern ].each do |modifier|
		candidate = self.fetch( key.send(modifier) ) if key.respond_to? modifier rescue false
		return candidate if candidate
	end

	return nil
end