| 7 | | # Converts the array to a comma-separated sentence where the last element is joined by the connector word. Options: |
|---|
| 8 | | # * <tt>:connector</tt> - The word used to join the last element in arrays with two or more elements (default: "and") |
|---|
| 9 | | # * <tt>:skip_last_comma</tt> - Set to true to return "a, b and c" instead of "a, b, and c". |
|---|
| | 7 | # Returns a comma-seperated string in which the last element of the |
|---|
| | 8 | # array is joined by a connector word. |
|---|
| | 9 | # |
|---|
| | 10 | # ==== Options |
|---|
| | 11 | # * <tt>:connector</tt> - The string used to join the last element in |
|---|
| | 12 | # arrays with two or more elements (default: <tt>"and"</tt>) |
|---|
| | 13 | # * <tt>:skip_last_comma</tt> - Set to +true+ to return |
|---|
| | 14 | # <tt>"a, b and c"</tt> instead of <tt>"a, b, and c"</tt> |
|---|
| | 15 | # |
|---|
| | 16 | # ==== Examples |
|---|
| | 17 | # ["Lions", "tigers", "bears"].to_sentence |
|---|
| | 18 | # # => "Lions, tigers, and bears" |
|---|
| | 19 | # |
|---|
| | 20 | # ["Active Record", "Action Pack", "Active Resource"].to_sentence(:connector => "or") |
|---|
| | 21 | # # => "Active Record, Action Pack, or Active Resource" |
|---|
| | 22 | # |
|---|
| | 23 | # ["red", "green", "blue"].to_sentence(:skip_last_comma => true) |
|---|
| | 24 | # # => "red, green and blue" |
|---|
| 26 | | |
|---|
| 27 | | # When an array is given to url_for, it is converted to a slash separated string. |
|---|
| | 41 | |
|---|
| | 42 | # Returns a slash-separated string from the array's elements. This |
|---|
| | 43 | # method is used by +url_for+. |
|---|
| | 44 | # |
|---|
| | 45 | # ==== Examples |
|---|
| | 46 | # ["accounts", "new", 3].to_param |
|---|
| | 47 | # # => "accounts/new/3" |
|---|
| | 48 | # |
|---|
| | 49 | # ["users", "opa2332", "pages", "personal"].to_param |
|---|
| | 50 | # # => "users/opa2332/pages/personal" |
|---|
| | 71 | # Returns a string from the array's elements. The string's composition |
|---|
| | 72 | # is determined by the +format+ parameter: |
|---|
| | 73 | # * <tt>:db</tt> - a comma-separated list of each element's response to |
|---|
| | 74 | # calling +id+, or <tt>"null"</tt> if the array is empty |
|---|
| | 75 | # * Otherwise, Ruby's default +to_s+ behavior is used. |
|---|
| | 76 | # |
|---|
| | 77 | # This method is also aliased as +to_s+. |
|---|
| | 78 | # |
|---|
| | 79 | # ==== Examples |
|---|
| | 80 | # ["Robert", "Kevin", "Ryan"].to_formatted_s # => "RobertKevinRyan" |
|---|
| | 81 | # |
|---|
| | 82 | # david = Person.find(1) |
|---|
| | 83 | # robert = Person.find(5) |
|---|
| | 84 | # [david, robert].to_formatted_s(:db) # => "1,5" |
|---|
| 60 | | |
|---|
| | 97 | |
|---|
| | 98 | # Attempts to return a string of XML from the array's elements. Each |
|---|
| | 99 | # element must respond to +to_xml+, or an error will be raised. |
|---|
| | 100 | # |
|---|
| | 101 | # ==== Options |
|---|
| | 102 | # * <tt>:root</tt> - The name of the root element (default: the |
|---|
| | 103 | # pluralized class name of the elements if they are homogeneous, or |
|---|
| | 104 | # <tt>"records"</tt> otherwise) |
|---|
| | 105 | # * <tt>:children</tt> - The name of the child elements (default: the |
|---|
| | 106 | # singular version of the root element's name) |
|---|
| | 107 | # * <tt>:indent</tt> - Number of spaces to indent the XML (default: |
|---|
| | 108 | # <tt>2</tt>) |
|---|
| | 109 | # * <tt>:builder</tt> - The Builder instance to use to generate the XML |
|---|
| | 110 | # (default: a new instance of <tt>Builder::XmlMarkup</tt>) |
|---|
| | 111 | # * <tt>:dasherize</tt> - Whether to use dashes instead of underscores |
|---|
| | 112 | # when formatting the root element's name (default: +true+) |
|---|
| | 113 | # * <tt>:skip_instruct</tt> - Whether to omit the XML declaration from |
|---|
| | 114 | # the beginning of the string (default: +false+) |
|---|
| | 115 | # * <tt>:skip_types</tt> - Whether to omit the +type+ attributes from |
|---|
| | 116 | # the XML tags, such as <tt>type="array"</tt> (default: +false+) |
|---|
| | 117 | # |
|---|
| | 118 | # If a block is given, it will be called with the Builder instance so |
|---|
| | 119 | # that you can insert arbitrary XML or adjust Builder options before the |
|---|
| | 120 | # array elements are processed. |
|---|
| | 121 | # |
|---|
| | 122 | # ==== Examples |
|---|
| | 123 | # |
|---|
| | 124 | # [1, 2, 3].to_xml |
|---|
| | 125 | # # => RuntimeError: Not all elements respond to to_xml |
|---|
| | 126 | # |
|---|
| | 127 | # [{'key' => 'value', 'key2' => 'value'}, {'name' => 'Ruby on Rails'}].to_xml |
|---|
| | 128 | # # => '<?xml version="1.0" encoding="UTF-8"?> |
|---|
| | 129 | # <records type="array"> |
|---|
| | 130 | # <record> |
|---|
| | 131 | # <key2>value</key2> |
|---|
| | 132 | # <key>value</key> |
|---|
| | 133 | # </record> |
|---|
| | 134 | # <record> |
|---|
| | 135 | # <name>Ruby on Rails</name> |
|---|
| | 136 | # </record> |
|---|
| | 137 | # </records>' |
|---|
| | 138 | # |
|---|
| | 139 | # [{'color' => 'orange'}].to_xml(:root => 'vegetables', :children => 'carrot') |
|---|
| | 140 | # # => '<?xml version="1.0" encoding="UTF-8"?> |
|---|
| | 141 | # <vegetables type="array"> |
|---|
| | 142 | # <carrot> |
|---|
| | 143 | # <color>orange</color> |
|---|
| | 144 | # </carrot> |
|---|
| | 145 | # </beets>' |
|---|
| | 146 | # |
|---|
| | 147 | # [{'height' => 1.8}].to_xml(:root => 'people') { |xml| |
|---|
| | 148 | # xml.comment!('All measurements are in meters.') |
|---|
| | 149 | # } |
|---|
| | 150 | # # => '<?xml version="1.0" encoding="UTF-8"?> |
|---|
| | 151 | # <people type="array"> |
|---|
| | 152 | # <!-- All measurements are in meters. --> |
|---|
| | 153 | # <person> |
|---|
| | 154 | # <height type="float">1.8</height> |
|---|
| | 155 | # </person> |
|---|
| | 156 | # </people>' |
|---|