Skip to content
Browse files

Performance: minor Array#to_param and #to_query speedups

  • Loading branch information...
1 parent 69e72af commit 6874caa4070f10cdbe104c9ac97dafd33dbdd282 @jeremy jeremy committed Jun 24, 2008
Showing with 3 additions and 2 deletions.
  1. +3 −2 activesupport/lib/active_support/core_ext/array/conversions.rb
View
5 activesupport/lib/active_support/core_ext/array/conversions.rb
@@ -27,15 +27,16 @@ def to_sentence(options = {})
# 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
- map(&:to_param).join '/'
+ collect { |e| e.to_param }.join '/'
end
# Converts an array into a string suitable for use as a URL query string,
# using the given +key+ as the param name.
#
# ['Rails', 'coding'].to_query('hobbies') # => "hobbies%5B%5D=Rails&hobbies%5B%5D=coding"
def to_query(key)
- collect { |value| value.to_query("#{key}[]") } * '&'
+ prefix = "#{key}[]"
+ collect { |value| value.to_query(prefix) }.join '&'
end
def self.included(base) #:nodoc:

0 comments on commit 6874caa

Please sign in to comment.
Something went wrong with that request. Please try again.