Methods
Public Instance methods
When an array is given to url_for, it is converted to a slash separated string.
[ show source ]
# File vendor/rails/activesupport/lib/active_support/core_ext/array/conversions.rb, line 25 25: def to_param 26: join '/' 27: end
Converts the array to comma-seperated sentence where the last element is joined by the connector word. Options:
- :connector: The word used to join the last element in arrays with more than two elements (default: "and")
- :skip_last_comma: Set to true to return "a, b, and c" instead of "a, b and c".
[ show source ]
# File vendor/rails/activesupport/lib/active_support/core_ext/array/conversions.rb, line 8 8: def to_sentence(options = {}) 9: options.assert_valid_keys(:connector, :skip_last_comma) 10: options.reverse_merge! :connector => 'and', :skip_last_comma => false 11: 12: case length 13: when 0 14: "" 15: when 1 16: self[0] 17: when 2 18: "#{self[0]} #{options[:connector]} #{self[1]}" 19: else 20: "#{self[0...-1].join(', ')}#{options[:skip_last_comma] ? '' : ','} #{options[:connector]} #{self[-1]}" 21: end 22: end
[ show source ]
# File vendor/rails/activesupport/lib/active_support/core_ext/array/conversions.rb, line 29 29: def to_xml(options = {}) 30: raise "Not all elements respond to to_xml" unless all? { |e| e.respond_to? :to_xml } 31: 32: options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? first.class.to_s.underscore.pluralize : "records" 33: options[:children] ||= options[:root].singularize 34: options[:indent] ||= 2 35: options[:builder] ||= Builder::XmlMarkup.new(:indent => options[:indent]) 36: 37: root = options.delete(:root) 38: children = options.delete(:children) 39: 40: options[:builder].instruct! unless options.delete(:skip_instruct) 41: options[:builder].tag!(root.to_s.dasherize) { each { |e| e.to_xml(options.merge({ :skip_instruct => true, :root => children })) } } 42: end