Sha256: e588043dc9c45387e1ac4f69aff7248be0ce4ff47ef8566b511496392f259717
Contents?: true
Size: 787 Bytes
Versions: 2
Compression:
Stored size: 787 Bytes
Contents
# frozen_string_literal: true # Big thanks to Tim Ruffles (https://github.com/timruffles) # https://gist.github.com/timruffles/2780508 module HashConverter class << self def to_underscore(hash) convert(hash, :underscore) end def to_string(hash) convert(hash, :to_s) end def to_sym(hash) convert(hash, :to_sym) end # FIXME: not sure it will be ever needed # def to_camel_case hash # convert hash, :camelize, :lower # end def convert(obj, *method) case obj when Hash obj.each_with_object({}) do |(k, v), h| v = convert(v, *method) h[k.send(*method)] = v end when Array obj.map { |m| convert(m, *method) } else obj end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
locomotivecms_common-0.6.0.alpha1 | lib/locomotive/common/core_ext/hash.rb |
locomotivecms_common-0.5.0 | lib/locomotive/common/core_ext/hash.rb |