diff options
author | Michael Koziarski <michael@koziarski.com> | 2007-12-02 00:28:30 +0000 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2007-12-02 00:28:30 +0000 |
commit | 67442cb40d0850f42ff66a66e2c2b3f5cf5feb07 (patch) | |
tree | a256ff8cd19105da9b86659c1c71cb4b90b5d574 /activesupport/lib/active_support | |
parent | c01c28c3047bbf0be2861c7ae1146723cf4ff7a9 (diff) | |
download | rails-67442cb40d0850f42ff66a66e2c2b3f5cf5feb07.tar.gz rails-67442cb40d0850f42ff66a66e2c2b3f5cf5feb07.tar.bz2 rails-67442cb40d0850f42ff66a66e2c2b3f5cf5feb07.zip |
Fix potential extra space in Array#to_sentence. Closes #10327 [kamal]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8251 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r-- | activesupport/lib/active_support/core_ext/array/conversions.rb | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb index 56c7cf1d71..8f72294838 100644 --- a/activesupport/lib/active_support/core_ext/array/conversions.rb +++ b/activesupport/lib/active_support/core_ext/array/conversions.rb @@ -10,16 +10,17 @@ module ActiveSupport #:nodoc: def to_sentence(options = {}) options.assert_valid_keys(:connector, :skip_last_comma) options.reverse_merge! :connector => 'and', :skip_last_comma => false - + options[:connector] = "#{options[:connector]} " unless options[:connector].nil? || options[:connector].strip == '' + case length - when 0 - "" + when 0 + "" when 1 self[0] when 2 - "#{self[0]} #{options[:connector]} #{self[1]}" + "#{self[0]} #{options[:connector]}#{self[1]}" else - "#{self[0...-1].join(', ')}#{options[:skip_last_comma] ? '' : ','} #{options[:connector]} #{self[-1]}" + "#{self[0...-1].join(', ')}#{options[:skip_last_comma] ? '' : ','} #{options[:connector]}#{self[-1]}" end end @@ -47,7 +48,7 @@ module ActiveSupport #:nodoc: to_default_s end end - + def to_xml(options = {}) raise "Not all elements respond to to_xml" unless all? { |e| e.respond_to? :to_xml } |