Sha256: 2eb6e7ee88b14b177defe7d114b4027d3c8c4151e73c5fad3c92adea8d9c59e1
Contents?: true
Size: 1.31 KB
Versions: 8
Compression:
Stored size: 1.31 KB
Contents
# -*- coding: utf-8 -*- require 'tengine/support/core_ext/hash/deep_dup' class Hash # Return a new hash with all keys converted to strings recursively. def deep_stringify_keys deep_dup.deep_stringify_keys! end # Destructively convert all keys to strings recursively. def deep_stringify_keys! stringify_keys! # active_support/core_ext/hash/keysのメソッドをそのまま使う values.each do |value| if value.respond_to?(:deep_stringify_keys!) value.deep_stringify_keys! elsif value.respond_to?(:each) value.each{|v| v.deep_stringify_keys! if v.respond_to?(:deep_stringify_keys!)} end end self end # Return a new hash with all keys converted to symbols recursively, as long as # they respond to +to_sym+. def deep_symbolize_keys deep_dup.deep_symbolize_keys! end # Destructively convert all keys to symbols recursively, as long as they respond # to +to_sym+. def deep_symbolize_keys! symbolize_keys! # active_support/core_ext/hash/keysのメソッドをそのまま使う values.each do |value| if value.respond_to?(:deep_symbolize_keys!) value.deep_symbolize_keys! elsif value.respond_to?(:each) value.each{|v| v.deep_symbolize_keys! if v.respond_to?(:deep_symbolize_keys!)} end end self end end
Version data entries
8 entries across 8 versions & 1 rubygems