Module: Rocket::Helpers

Defined in:
lib/rocket/helpers.rb

Instance Method Summary collapse

Instance Method Details

#symbolize_keys(hash) ⇒ Object

Hash given, returns it version with symbolized keys.

p symbolize_keys("hello" => "world", ["Array here"] => "yup")
p symbolize_keys(:one => 1, "two" => 2)

produces:

{:hello => "world", ["Array here"] => "yup"}
{:one => 1, :two => 2}


14
15
16
17
18
19
20
# File 'lib/rocket/helpers.rb', line 14

def symbolize_keys(hash)
  return hash unless hash.is_a?(Hash)
  hash.inject({}) do |options, (key, value)|
    options[(key.to_sym if key.respond_to?(:to_sym)) || key] = value
    options
  end
end