Sha256: 4378a20057fa46e945bd39ea831da19ed2a7117c5021082ec967218d4befe8ec

Contents?: true

Size: 1023 Bytes

Versions: 8

Compression:

Stored size: 1023 Bytes

Contents


class Object
  # Alias of <tt>to_s</tt>.
  def to_param
    to_s
  end
end

class NilClass
  def to_param
    self
  end
end

class TrueClass
  def to_param
    self
  end
end

class FalseClass
  def to_param
    self
  end
end

class Array
  # Calls <tt>to_param</tt> on all its elements and joins the result with
  # slashes. This is used by <tt>url_for</tt> in Action Pack.
  def to_param
    collect { |e| e.to_param }.join '/'
  end
end

class Hash
  # Converts a hash into a string suitable for use as a URL query string. An optional <tt>namespace</tt> can be
  # passed to enclose the param names (see example below).
  #
  # ==== Examples
  #   { :name => 'David', :nationality => 'Danish' }.to_param # => "name=David&nationality=Danish"
  #
  #   { :name => 'David', :nationality => 'Danish' }.to_param('user') # => "user[name]=David&user[nationality]=Danish"
  def to_param(namespace = nil)
    collect do |key, value|
      value.to_query(namespace ? "#{namespace}[#{key}]" : key)
    end.sort * '&'
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
csd-0.1.5 lib/active_support/core_ext/object/to_param.rb
csd-0.1.4 lib/active_support/core_ext/object/to_param.rb
csd-0.1.3 lib/active_support/core_ext/object/to_param.rb
csd-0.1.2 lib/active_support/core_ext/object/to_param.rb
csd-0.1.1 lib/active_support/core_ext/object/to_param.rb
csd-0.1.0 lib/active_support/core_ext/object/to_param.rb
csd-0.0.16 lib/active_support/core_ext/object/to_param.rb
activesupport-3.0.0.beta4 lib/active_support/core_ext/object/to_param.rb