aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/array/conversions.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/core_ext/array/conversions.rb')
-rw-r--r--activesupport/lib/active_support/core_ext/array/conversions.rb23
1 files changed, 18 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/core_ext/array/conversions.rb b/activesupport/lib/active_support/core_ext/array/conversions.rb
index 69d35dafd3..ba8e022fb2 100644
--- a/activesupport/lib/active_support/core_ext/array/conversions.rb
+++ b/activesupport/lib/active_support/core_ext/array/conversions.rb
@@ -6,14 +6,27 @@ module ActiveSupport #:nodoc:
# * <tt>:words_connector</tt> - The sign or word used to join the elements in arrays with two or more elements (default: ", ")
# * <tt>:two_words_connector</tt> - The sign or word used to join the elements in arrays with two elements (default: " and ")
# * <tt>:last_word_connector</tt> - The sign or word used to join the last element in arrays with three or more elements (default: ", and ")
- def to_sentence(options = {})
- options.assert_valid_keys(:words_connector, :two_words_connector, :last_word_connector, :locale)
-
- default_words_connector = I18n.translate(:'support.array.words_connector', :locale => options[:locale])
+ def to_sentence(options = {})
+ default_words_connector = I18n.translate(:'support.array.words_connector', :locale => options[:locale])
default_two_words_connector = I18n.translate(:'support.array.two_words_connector', :locale => options[:locale])
default_last_word_connector = I18n.translate(:'support.array.last_word_connector', :locale => options[:locale])
- options.reverse_merge! :words_connector => default_words_connector, :two_words_connector => default_two_words_connector, :last_word_connector => default_last_word_connector
+ # Try to emulate to_senteces previous to 2.3
+ if options.has_key?(:connector) || options.has_key?(:skip_last_comma)
+ ::ActiveSupport::Deprecation.warn(":connector has been deprecated. Use :words_connector instead", caller) if options.has_key? :connector
+ ::ActiveSupport::Deprecation.warn(":skip_last_comma has been deprecated. Use :last_word_connector instead", caller) if options.has_key? :skip_last_comma
+
+ skip_last_comma = options.delete :skip_last_comma
+ if connector = options.delete(:connector)
+ options[:last_word_connector] ||= skip_last_comma ? connector : ", #{connector}"
+ else
+ options[:last_word_connector] ||= skip_last_comma ? default_two_words_connector : default_last_word_connector
+ end
+ end
+
+ options.assert_valid_keys(:words_connector, :two_words_connector, :last_word_connector, :locale)
+ options.reverse_merge! :words_connector => default_words_connector, :two_words_connector => default_two_words_connector, :last_word_connector => default_last_word_connector
+
case length
when 0
""