GitHub
6ca05c68

sferik/rails_admin

A

Hash

Updated 3 months ago.
25
Complexity
12.4
Complexity / M
0
Duplication
1
Churn
43
Lines
42
Lines of Code
2
Methods
21
LOC / Method

No issues to see here. Woot.

class Hash
  def symbolize
    Hash.symbolize_hash(self)
  end

  def self.symbolize_hash(obj)
    case obj
    when Array
      obj.inject([])do|res, val|
        res << case val
        when Hash, Array
          symbolize_hash(val)
        when String
          val.to_sym
        else
          val
        end
        res
      end
    when Hash
      obj.inject({})do|res, (key, val)|
        nkey = case key
        when String
          key.to_sym
        else
          key
        end
        nval = case val
        when Hash, Array
          symbolize_hash(val)
        when String
          val.to_sym
        else
          val
        end
        res[nkey] = nval
        res
      end
    else
      obj
    end
  end
end