Home

小鱼驿站

12 Jan 2014

Transform Hash Key Type In Rails

Symbol To String

foo = {
    :a => 1,
    :b => 2
}

foo.with_indifferent_access
=>
{
    "a" => 1,
    "b" => 2
}

String To Symbol

foo = {
    "a" => 1,
    "b" => 2
}

foo.symbolize_keys
=>
{
    :a => 1,
    :b => 2
}

Til next time,
small_fish__ at 15:11

scribble