diff --git a/lib/shoryuken/core_ext.rb b/lib/shoryuken/core_ext.rb index 1141ba27..55fcb7bc 100644 --- a/lib/shoryuken/core_ext.rb +++ b/lib/shoryuken/core_ext.rb @@ -1,37 +1,50 @@ -begin - require 'active_support/core_ext/hash/keys' - require 'active_support/core_ext/hash/deep_merge' - {}.stringify_keys - {}.symbolize_keys - {}.deep_symbolize_keys -rescue LoadError, NoMethodError - class Hash - def stringify_keys - keys.each do |key| - self[key.to_s] = delete(key) +module Shoryuken + module CoreExt + module StringifyKeys + def stringify_keys + keys.each do |key| + self[key.to_s] = delete(key) + end + self end - self - end if !{}.respond_to?(:stringify_keys) + end - def symbolize_keys - keys.each do |key| - self[(key.to_sym rescue key) || key] = delete(key) + module SymbolizeKeys + def symbolize_keys + keys.each do |key| + self[(key.to_sym rescue key) || key] = delete(key) + end + self end - self - end if !{}.respond_to?(:symbolize_keys) + end - def deep_symbolize_keys - keys.each do |key| - value = delete(key) - self[(key.to_sym rescue key) || key] = value + module DeepSymbolizeKeys + def deep_symbolize_keys + keys.each do |key| + value = delete(key) + self[(key.to_sym rescue key) || key] = value - value.deep_symbolize_keys if value.is_a? Hash + value.deep_symbolize_keys if value.is_a? Hash + end + self end - self - end if !{}.respond_to?(:deep_symbolize_keys) + end end end +begin + require 'active_support/core_ext/hash/keys' + require 'active_support/core_ext/hash/deep_merge' +rescue LoadError +end + +class Hash + include Shoryuken::CoreExt::StringifyKeys if !method_defined?(:stringify_keys) + include Shoryuken::CoreExt::SymbolizeKeys if !method_defined?(:symbolize_keys) + include Shoryuken::CoreExt::DeepSymbolizeKeys if !method_defined?(:deep_symbolize_keys) +end + + begin require 'active_support/core_ext/string/inflections' rescue LoadError