Sha256: 20c8939396eda29cb9e7f1e5c85e7b27d1643fdcaaf7d07f506e50129763047f

Contents?: true

Size: 1.58 KB

Versions: 35

Compression:

Stored size: 1.58 KB

Contents

module Shoryuken
  module HashExt
    module StringifyKeys
      def stringify_keys
        keys.each do |key|
          self[key.to_s] = delete(key)
        end
        self
      end
    end

    module SymbolizeKeys
      def symbolize_keys
        keys.each do |key|
          self[(key.to_sym rescue key) || key] = delete(key)
        end
        self
      end
    end

    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
        end
        self
      end
    end
  end

  module StringExt
    module Constantize
      def constantize
        names = self.split('::')
        names.shift if names.empty? || names.first.empty?

        constant = Object
        names.each do |name|
          constant = constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
        end
        constant
      end
    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::HashExt::StringifyKeys unless method_defined?(:stringify_keys)
  include Shoryuken::HashExt::SymbolizeKeys unless method_defined?(:symbolize_keys)
  include Shoryuken::HashExt::DeepSymbolizeKeys unless method_defined?(:deep_symbolize_keys)
end

begin
  require 'active_support/core_ext/string/inflections'
rescue LoadError
end

class String
  include Shoryuken::StringExt::Constantize unless method_defined?(:constantize)
end

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
shoryuken-3.2.3 lib/shoryuken/core_ext.rb
shoryuken-3.2.2 lib/shoryuken/core_ext.rb
shoryuken-3.2.1 lib/shoryuken/core_ext.rb
shoryuken-3.2.0 lib/shoryuken/core_ext.rb
shoryuken-3.1.12 lib/shoryuken/core_ext.rb
shoryuken-3.1.11 lib/shoryuken/core_ext.rb
shoryuken-3.1.10 lib/shoryuken/core_ext.rb
shoryuken-3.1.9 lib/shoryuken/core_ext.rb
shoryuken-3.1.8 lib/shoryuken/core_ext.rb
shoryuken-3.1.7 lib/shoryuken/core_ext.rb
shoryuken-3.1.6 lib/shoryuken/core_ext.rb
shoryuken-3.1.5 lib/shoryuken/core_ext.rb
shoryuken-3.1.4 lib/shoryuken/core_ext.rb
shoryuken-3.1.3 lib/shoryuken/core_ext.rb
shoryuken-3.1.2 lib/shoryuken/core_ext.rb
shoryuken-3.1.1 lib/shoryuken/core_ext.rb
shoryuken-3.1.0 lib/shoryuken/core_ext.rb
shoryuken-3.0.11 lib/shoryuken/core_ext.rb
shoryuken-3.0.10 lib/shoryuken/core_ext.rb
shoryuken-3.0.9 lib/shoryuken/core_ext.rb