Sha256: 43a3d63e8bb52972138223d6ab4d6414a9386276433707c4011912bab6d736f5
Contents?: true
Size: 1.35 KB
Versions: 8
Compression:
Stored size: 1.35 KB
Contents
# -*- coding: utf-8 -*- require 'tengine/support/core_ext/hash/deep_dup' require 'active_support/core_ext/hash/keys' 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