Sha256: aab27f8e3a6a7b98cecddf3f4ce0785fa97f33889fa2c5fcd72a1d29f28dd0a3

Contents?: true

Size: 1.11 KB

Versions: 37

Compression:

Stored size: 1.11 KB

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). The string pairs "key=value" that conform the query
  # string are sorted lexicographically in ascending order.
  #
  # ==== 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

37 entries across 37 versions & 2 rubygems

Version Path
activesupport-3.0.20 lib/active_support/core_ext/object/to_param.rb
activesupport-3.0.19 lib/active_support/core_ext/object/to_param.rb
activesupport-3.0.18 lib/active_support/core_ext/object/to_param.rb
activesupport-3.0.17 lib/active_support/core_ext/object/to_param.rb
activesupport-3.0.16 lib/active_support/core_ext/object/to_param.rb
activesupport-3.0.15 lib/active_support/core_ext/object/to_param.rb
activesupport-3.0.14 lib/active_support/core_ext/object/to_param.rb
activesupport-3.0.13 lib/active_support/core_ext/object/to_param.rb
activesupport-3.0.13.rc1 lib/active_support/core_ext/object/to_param.rb
activesupport-3.0.12 lib/active_support/core_ext/object/to_param.rb
activesupport-3.0.12.rc1 lib/active_support/core_ext/object/to_param.rb
activesupport-3.0.11 lib/active_support/core_ext/object/to_param.rb
messagebus_ruby_api-0.4.7 spec/ruby/1.9.1/gems/activesupport-3.0.9/lib/active_support/core_ext/object/to_param.rb
messagebus_ruby_api-0.4.4 spec/ruby/1.9.1/gems/activesupport-3.0.9/lib/active_support/core_ext/object/to_param.rb
activesupport-3.0.10 lib/active_support/core_ext/object/to_param.rb
activesupport-3.0.10.rc1 lib/active_support/core_ext/object/to_param.rb
activesupport-3.0.9 lib/active_support/core_ext/object/to_param.rb
activesupport-3.0.9.rc5 lib/active_support/core_ext/object/to_param.rb
activesupport-3.0.9.rc4 lib/active_support/core_ext/object/to_param.rb
activesupport-3.0.9.rc3 lib/active_support/core_ext/object/to_param.rb