Permalink
Browse files

figured out how to create a hash with indifferent access.

  • Loading branch information...
1 parent 86406a3 commit 34e75a689a0ee6eada012f6bd4a6139a04d43846 @davidvgus committed May 19, 2012
Showing with 20 additions and 0 deletions.
  1. +20 −0 indiffhash.rb
View
@@ -0,0 +1,20 @@
+class IndiffHash
+
+ def self.[](*values)
+ self.new(values)
+ end
+
+ def initialize(values = [])
+ @hash = Hash[*values]
+ @hash = @hash.inject({}){|memo,(k,v)| memo[k.to_sym] = v; memo}
+ end
+
+ def [](index)
+ @hash[index.to_sym]
+ end
+
+ def []=(index, value)
+ @hash[index.to_sym] = value
+ end
+
+end

0 comments on commit 34e75a6

Please sign in to comment.