Sha256: bd55e7d95a06fe3542d17c3abeeba2246598eb93252f138b23ce50eb4e913d58

Contents?: true

Size: 597 Bytes

Versions: 4

Compression:

Stored size: 597 Bytes

Contents

module VaultedBilling
  module CoreExt
    module Hash
      def to_querystring
        to_a.reject { |pair| pair.last.nil? }.
          sort_by { |item| item.first.to_s }.
          collect { |key, value| "#{key}=#{value}" }.join('&')
      end

      module ClassMethods
        def from_querystring(string)
          ::Hash[string.split(/&/).
            collect { |i| i.split(/=/) }.
            collect { |e| e.size == 1 ? (e << '') : e }]
        end
      end
    end
  end
end

::Hash.send :include, VaultedBilling::CoreExt::Hash
::Hash.extend(VaultedBilling::CoreExt::Hash::ClassMethods)

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vaulted_billing-0.0.3 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-0.0.2 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-0.0.1 lib/vaulted_billing/core_ext/hash.rb
vaulted_billing-0.0.0 lib/vaulted_billing/core_ext/hash.rb