Sha256: e5afecbcf73c036459c637e16d1c20ead345ff7602a4125b800e4c1c86547ef3

Contents?: true

Size: 655 Bytes

Versions: 10

Compression:

Stored size: 655 Bytes

Contents

module Waves
  module Ext # :nodoc:
    
    # Utility methods mixed into Hash.
    module Hash
      
      # Return a copy of the hash where all keys have been converted to strings.
      def stringify_keys
        inject({}) do |options, (key, value)|
          options[key.to_s] = value
          options
        end
      end

      # Destructively convert all keys to symbols.
      def symbolize_keys!
        keys.each do |key|
          unless key.is_a?(Symbol)
            self[key.to_sym] = self[key]
            delete(key)
          end
        end
        self
      end
    end
  end
end

class Hash # :nodoc:
  include Waves::Ext::Hash
end

Version data entries

10 entries across 10 versions & 4 rubygems

Version Path
dyoder-waves-0.8.0 lib/ext/hash.rb
waves-edge-2009.03.10.13.14 lib/ext/hash.rb
waves-stable-2009.3.10 lib/ext/hash.rb
waves-0.9.3 lib/waves/ext/hash.rb
waves-0.9.2 lib/waves/ext/hash.rb
waves-0.9.1 lib/waves/ext/hash.rb
waves-0.9.0 lib/waves/ext/hash.rb
waves-0.8.1 lib/ext/hash.rb
waves-0.8.0 lib/ext/hash.rb
waves-0.8.2 lib/ext/hash.rb