Changeset 3816
- Timestamp:
- 03/08/06 16:13:13 (3 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/activesupport/lib/active_support/core_ext/array/conversions.rb
r3812 r3816 5 5 # Converts the array to comma-seperated sentence where the last element is joined by the connector word. Options: 6 6 # * <tt>:connector</tt>: The word used to join the last element in arrays with more than two elements (default: "and") 7 # * <tt>:skip_last_comma</tt>: Set to false to return "a, b, and c" instead of "a, b and c".7 # * <tt>:skip_last_comma</tt>: Set to true to return "a, b, and c" instead of "a, b and c". 8 8 def to_sentence(options = {}) 9 9 options.assert_valid_keys(:connector, :skip_last_comma) 10 options.reverse_merge! :connector => 'and', :skip_last_comma => true10 options.reverse_merge! :connector => 'and', :skip_last_comma => false 11 11 12 12 case length trunk/activesupport/test/core_ext/array_ext_test.rb
r3812 r3816 19 19 assert_equal "one", ['one'].to_sentence 20 20 assert_equal "one and two", ['one', 'two'].to_sentence 21 assert_equal "one, two and three", ['one', 'two', 'three'].to_sentence21 assert_equal "one, two, and three", ['one', 'two', 'three'].to_sentence 22 22 23 23 end 24 24 25 25 def test_to_sentence_with_connector 26 assert_equal "one, two and also three", ['one', 'two', 'three'].to_sentence(:connector => 'and also')26 assert_equal "one, two, and also three", ['one', 'two', 'three'].to_sentence(:connector => 'and also') 27 27 end 28 28