Sha256: 656e213e0ba19f72d69515c90fe29a34da3bb30a03d31f6854c344dd2105c7d4

Contents?: true

Size: 443 Bytes

Versions: 10

Compression:

Stored size: 443 Bytes

Contents

class Object
  def to_query(key)
    require 'cgi' unless defined?(CGI) && defined?(CGI::escape)
    "#{CGI.escape(key.to_s)}=#{CGI.escape(to_s)}"
  end
end

class Array
  def to_query(key)
    prefix = "#{key}[]"
    collect { |value| value.to_query(prefix) }.join '&'
  end
end

class Hash
  def to_query(namespace = nil)
    collect do |key, value|
      value.to_query(namespace ? "#{namespace}[#{key}]" : key)
    end.sort * '&'
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
nurego-1.1.22 lib/nurego/extensions.rb
nurego-1.1.21 lib/nurego/extensions.rb
nurego-1.1.20 lib/nurego/extensions.rb
nurego-1.1.19 lib/nurego/extensions.rb
nurego-1.1.18 lib/nurego/extensions.rb
nurego-1.1.17 lib/nurego/extensions.rb
nurego-1.1.16 lib/nurego/extensions.rb
nurego-1.1.15 lib/nurego/extensions.rb
nurego-1.1.14 lib/nurego/extensions.rb
nurego-1.1.13 lib/nurego/extensions.rb