File: hash_helper.rb

package info (click to toggle)
ruby-rails-admin 0.8.1%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 2,492 kB
  • ctags: 1,292
  • sloc: ruby: 5,341; makefile: 3
file content (28 lines) | stat: -rw-r--r-- 724 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module RailsAdmin
  class HashHelper
    def self.symbolize(obj)
      case obj
      when Array
        obj.each_with_object([]) do |val, res|
          res << case val
                 when Hash, Array then symbolize(val)
                 when String      then val.to_sym
                 else val
                 end
        end
      when Hash
        obj.each_with_object({}) do |(key, val), res|
          nkey = key.is_a?(String) ? key.to_sym : key
          nval = case val
                 when Hash, Array then symbolize(val)
                 when String      then val.to_sym
                 else val
                 end
          res[nkey] = nval
        end
      else
        obj
      end
    end
  end
end