Skip to content

Commit

Permalink
figured out how to create a hash with indifferent access.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidvgus committed May 19, 2012
1 parent 86406a3 commit 34e75a6
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions indiffhash.rb
@@ -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.