Skip to content

Instantly share code, notes, and snippets.

@jkutner
Created February 26, 2013 19:33
Show Gist options
  • Save jkutner/5041382 to your computer and use it in GitHub Desktop.
Save jkutner/5041382 to your computer and use it in GitHub Desktop.
class SessionHash < Hash
#...
def [](key)
load_for_read!
@data[key.to_s]
end
def []=(key, value)
load_for_write!
@data[key.to_s] = value
end
end
def indifferent_params(object)
case object
when Hash
new_hash = indifferent_hash
object.each { |key, value| new_hash[key] = indifferent_params(value) }
new_hash
when Array
object.map { |item| indifferent_params(item) }
else
object
end
end
# Creates a Hash with indifferent access.
def indifferent_hash
Hash.new {|hash,key| hash[key.to_s] if Symbol === key }
end
@jkutner
Copy link
Author

jkutner commented Feb 26, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment