aboutsummaryrefslogtreecommitdiffstats
path: root/guides/source/active_support_core_extensions.md
diff options
context:
space:
mode:
authorPrem Sichanugrist <s@sikachu.com>2012-09-01 19:34:21 -0400
committerPrem Sichanugrist <s@sikac.hu>2012-09-17 15:54:22 -0400
commitc89c163a0e7df7b29ba33608742eaba09a058090 (patch)
tree446ff2dea30ba938426f7f2759a1facd9b085429 /guides/source/active_support_core_extensions.md
parent872b7af337196febc516cb6218ae3d07f01a11a8 (diff)
downloadrails-c89c163a0e7df7b29ba33608742eaba09a058090.tar.gz
rails-c89c163a0e7df7b29ba33608742eaba09a058090.tar.bz2
rails-c89c163a0e7df7b29ba33608742eaba09a058090.zip
Convert inline code tags to Markdown
Diffstat (limited to 'guides/source/active_support_core_extensions.md')
-rw-r--r--guides/source/active_support_core_extensions.md74
1 files changed, 37 insertions, 37 deletions
diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md
index 352bf00283..06edaa29f2 100644
--- a/guides/source/active_support_core_extensions.md
+++ b/guides/source/active_support_core_extensions.md
@@ -87,7 +87,7 @@ The following values are considered to be blank in a Rails application:
* any other object that responds to +empty?+ and it is empty.
-INFO: The predicate for strings uses the Unicode-aware character class <tt>[:space:]</tt>, so for example U+2029 (paragraph separator) is considered to be whitespace.
+INFO: The predicate for strings uses the Unicode-aware character class `[:space:]`, so for example U+2029 (paragraph separator) is considered to be whitespace.
WARNING: Note that numbers are not mentioned, in particular 0 and 0.0 are *not* blank.
@@ -348,7 +348,7 @@ account.to_query('company[name]')
so its output is ready to be used in a query string.
-Arrays return the result of applying +to_query+ to each element with <tt>_key_[]</tt> as key, and join the result with "&":
+Arrays return the result of applying +to_query+ to each element with `_key_[]` as key, and join the result with "&":
```ruby
[3.4, -45.6].to_query('sample')
@@ -1124,7 +1124,7 @@ NOTE: Defined in +active_support/core_ext/class/subclasses.rb+.
#### +descendants+
-The +descendants+ method returns all classes that are <tt>&lt;</tt> than its receiver:
+The +descendants+ method returns all classes that are `&lt;` than its receiver:
```ruby
class C; end
@@ -1180,7 +1180,7 @@ s # => "<script>...</script>"
It is your responsibility to ensure calling +html_safe+ on a particular string is fine.
-If you append onto a safe string, either in-place with +concat+/<tt><<</tt>, or with <tt>+</tt>, the result is a safe string. Unsafe arguments are escaped:
+If you append onto a safe string, either in-place with +concat+/`<<`, or with `+`, the result is a safe string. Unsafe arguments are escaped:
```ruby
"".html_safe + "<" # => "&lt;"
@@ -1204,7 +1204,7 @@ To insert something verbatim use the +raw+ helper rather than calling +html_safe
<%= raw @cms.current_template %> <%# inserts @cms.current_template as is %>
```
-or, equivalently, use <tt><%==</tt>:
+or, equivalently, use `<%==`:
```erb
<%== @cms.current_template %> <%# inserts @cms.current_template as is %>
@@ -1288,7 +1288,7 @@ NOTE: Defined in +active_support/core_ext/string/filters.rb+.
### +inquiry+
-The <tt>inquiry</tt> method converts a string into a +StringInquirer+ object making equality checks prettier.
+The `inquiry` method converts a string into a +StringInquirer+ object making equality checks prettier.
```ruby
"production".inquiry.production? # => true
@@ -1433,7 +1433,7 @@ The method +pluralize+ returns the plural of its receiver:
As the previous example shows, Active Support knows some irregular plurals and uncountable nouns. Built-in rules can be extended in +config/initializers/inflections.rb+. That file is generated by the +rails+ command and has instructions in comments.
-+pluralize+ can also take an optional +count+ parameter. If <tt>count == 1</tt> the singular form will be returned. For any other value of +count+ the plural form will be returned:
++pluralize+ can also take an optional +count+ parameter. If `count == 1` the singular form will be returned. For any other value of +count+ the plural form will be returned:
```ruby
"dude".pluralize(0) # => "dudes"
@@ -1511,7 +1511,7 @@ end
That may be handy to compute method names in a language that follows that convention, for example JavaScript.
-INFO: As a rule of thumb you can think of +camelize+ as the inverse of +underscore+, though there are cases where that does not hold: <tt>"SSLError".underscore.camelize</tt> gives back <tt>"SslError"</tt>. To support cases such as this, Active Support allows you to specify acronyms in +config/initializers/inflections.rb+:
+INFO: As a rule of thumb you can think of +camelize+ as the inverse of +underscore+, though there are cases where that does not hold: `"SSLError".underscore.camelize` gives back `"SslError"`. To support cases such as this, Active Support allows you to specify acronyms in +config/initializers/inflections.rb+:
```ruby
ActiveSupport::Inflector.inflections do |inflect|
@@ -1560,7 +1560,7 @@ def load_missing_constant(from_mod, const_name)
end
```
-INFO: As a rule of thumb you can think of +underscore+ as the inverse of +camelize+, though there are cases where that does not hold. For example, <tt>"SSLError".underscore.camelize</tt> gives back <tt>"SslError"</tt>.
+INFO: As a rule of thumb you can think of +underscore+ as the inverse of +camelize+, though there are cases where that does not hold. For example, `"SSLError".underscore.camelize` gives back `"SslError"`.
NOTE: Defined in +active_support/core_ext/string/inflections.rb+.
@@ -2038,7 +2038,7 @@ The method +sum+ adds the elements of an enumerable:
(1..100).sum # => 5050
```
-Addition only assumes the elements respond to <tt>+</tt>:
+Addition only assumes the elements respond to `+`:
```ruby
[[1, 2], [2, 3], [3, 4]].sum # => [1, 2, 2, 3, 3, 4]
@@ -2152,7 +2152,7 @@ NOTE: Defined in +active_support/core_ext/array/access.rb+.
#### +prepend+
-This method is an alias of <tt>Array#unshift</tt>.
+This method is an alias of `Array#unshift`.
```ruby
%w(a b c d).prepend('e') # => %w(e a b c d)
@@ -2163,7 +2163,7 @@ NOTE: Defined in +active_support/core_ext/array/prepend_and_append.rb+.
#### +append+
-This method is an alias of <tt>Array#<<</tt>.
+This method is an alias of `Array#<<`.
```ruby
%w(a b c d).append('e') # => %w(a b c d e)
@@ -2182,7 +2182,7 @@ User.exists?(:email => params[:email])
That syntactic sugar is used a lot in Rails to avoid positional arguments where there would be too many, offering instead interfaces that emulate named parameters. In particular it is very idiomatic to use a trailing hash for options.
-If a method expects a variable number of arguments and uses <tt>*</tt> in its declaration, however, such an options hash ends up being an item of the array of arguments, where it loses its role.
+If a method expects a variable number of arguments and uses `*` in its declaration, however, such an options hash ends up being an item of the array of arguments, where it loses its role.
In those cases, you may give an options hash a distinguished treatment with +extract_options!+. This method checks the type of the last item of an array. If it is a hash it pops it and returns it, otherwise it returns an empty hash.
@@ -2215,18 +2215,18 @@ The method +to_sentence+ turns an array into a string containing a sentence that
This method accepts three options:
-* <tt>:two_words_connector</tt>: What is used for arrays of length 2. Default is " and ".
-* <tt>:words_connector</tt>: What is used to join the elements of arrays with 3 or more elements, except for the last two. Default is ", ".
-* <tt>:last_word_connector</tt>: What is used to join the last items of an array with 3 or more elements. Default is ", and ".
+* `:two_words_connector`: What is used for arrays of length 2. Default is " and ".
+* `:words_connector`: What is used to join the elements of arrays with 3 or more elements, except for the last two. Default is ", ".
+* `:last_word_connector`: What is used to join the last items of an array with 3 or more elements. Default is ", and ".
The defaults for these options can be localised, their keys are:
|_. Option |_. I18n key |
-| <tt>:two_words_connector</tt> | <tt>support.array.two_words_connector</tt> |
-| <tt>:words_connector</tt> | <tt>support.array.words_connector</tt> |
-| <tt>:last_word_connector</tt> | <tt>support.array.last_word_connector</tt> |
+| `:two_words_connector` | `support.array.two_words_connector` |
+| `:words_connector` | `support.array.words_connector` |
+| `:last_word_connector` | `support.array.last_word_connector` |
-Options <tt>:connector</tt> and <tt>:skip_last_comma</tt> are deprecated.
+Options `:connector` and `:skip_last_comma` are deprecated.
NOTE: Defined in +active_support/core_ext/array/conversions.rb+.
@@ -2234,7 +2234,7 @@ NOTE: Defined in +active_support/core_ext/array/conversions.rb+.
The method +to_formatted_s+ acts like +to_s+ by default.
-If the array contains items that respond to +id+, however, it may be passed the symbol <tt>:db</tt> as argument. That's typically used with collections of ARs. Returned strings are:
+If the array contains items that respond to +id+, however, it may be passed the symbol `:db` as argument. That's typically used with collections of ARs. Returned strings are:
```ruby
[].to_formatted_s(:db) # => "null"
@@ -2272,7 +2272,7 @@ Contributor.limit(2).order(:rank).to_xml
To do so it sends +to_xml+ to every item in turn, and collects the results under a root node. All items must respond to +to_xml+, an exception is raised otherwise.
-By default, the name of the root element is the underscorized and dasherized plural of the name of the class of the first item, provided the rest of elements belong to that type (checked with <tt>is_a?</tt>) and they are not hashes. In the example above that's "contributors".
+By default, the name of the root element is the underscorized and dasherized plural of the name of the class of the first item, provided the rest of elements belong to that type (checked with `is_a?`) and they are not hashes. In the example above that's "contributors".
If there's any element that does not belong to the type of the first one the root node becomes "objects":
@@ -2319,11 +2319,11 @@ If the receiver is an array of hashes the root element is by default also "objec
# </objects>
```
-WARNING. If the collection is empty the root element is by default "nil-classes". That's a gotcha, for example the root element of the list of contributors above would not be "contributors" if the collection was empty, but "nil-classes". You may use the <tt>:root</tt> option to ensure a consistent root element.
+WARNING. If the collection is empty the root element is by default "nil-classes". That's a gotcha, for example the root element of the list of contributors above would not be "contributors" if the collection was empty, but "nil-classes". You may use the `:root` option to ensure a consistent root element.
-The name of children nodes is by default the name of the root node singularized. In the examples above we've seen "contributor" and "object". The option <tt>:children</tt> allows you to set these node names.
+The name of children nodes is by default the name of the root node singularized. In the examples above we've seen "contributor" and "object". The option `:children` allows you to set these node names.
-The default XML builder is a fresh instance of <tt>Builder::XmlMarkup</tt>. You can configure your own builder via the <tt>:builder</tt> option. The method also accepts options like <tt>:dasherize</tt> and friends, they are forwarded to the builder:
+The default XML builder is a fresh instance of `Builder::XmlMarkup`. You can configure your own builder via the `:builder` option. The method also accepts options like `:dasherize` and friends, they are forwarded to the builder:
```ruby
Contributor.limit(2).order(:rank).to_xml(:skip_types => true)
@@ -2363,10 +2363,10 @@ Array.wrap([1, 2, 3]) # => [1, 2, 3]
Array.wrap(0) # => [0]
```
-This method is similar in purpose to <tt>Kernel#Array</tt>, but there are some differences:
+This method is similar in purpose to `Kernel#Array`, but there are some differences:
-* If the argument responds to +to_ary+ the method is invoked. <tt>Kernel#Array</tt> moves on to try +to_a+ if the returned value is +nil+, but <tt>Array.wrap</tt> returns +nil+ right away.
-* If the returned value from +to_ary+ is neither +nil+ nor an +Array+ object, <tt>Kernel#Array</tt> raises an exception, while <tt>Array.wrap</tt> does not, it just returns the value.
+* If the argument responds to +to_ary+ the method is invoked. `Kernel#Array` moves on to try +to_a+ if the returned value is +nil+, but `Array.wrap` returns +nil+ right away.
+* If the returned value from +to_ary+ is neither +nil+ nor an +Array+ object, `Kernel#Array` raises an exception, while `Array.wrap` does not, it just returns the value.
* It does not call +to_a+ on the argument, though special-cases +nil+ to return an empty array.
The last point is particularly worth comparing for some enumerables:
@@ -2382,9 +2382,9 @@ There's also a related idiom that uses the splat operator:
[*object]
```
-which in Ruby 1.8 returns +[nil]+ for +nil+, and calls to <tt>Array(object)</tt> otherwise. (Please if you know the exact behavior in 1.9 contact fxn.)
+which in Ruby 1.8 returns +[nil]+ for +nil+, and calls to `Array(object)` otherwise. (Please if you know the exact behavior in 1.9 contact fxn.)
-Thus, in this case the behavior is different for +nil+, and the differences with <tt>Kernel#Array</tt> explained above apply to the rest of +object+s.
+Thus, in this case the behavior is different for +nil+, and the differences with `Kernel#Array` explained above apply to the rest of +object+s.
NOTE: Defined in +active_support/core_ext/array/wrap.rb+.
@@ -2520,15 +2520,15 @@ The method +to_xml+ returns a string containing an XML representation of its rec
To do so, the method loops over the pairs and builds nodes that depend on the _values_. Given a pair +key+, +value+:
-* If +value+ is a hash there's a recursive call with +key+ as <tt>:root</tt>.
+* If +value+ is a hash there's a recursive call with +key+ as `:root`.
-* If +value+ is an array there's a recursive call with +key+ as <tt>:root</tt>, and +key+ singularized as <tt>:children</tt>.
+* If +value+ is an array there's a recursive call with +key+ as `:root`, and +key+ singularized as `:children`.
-* If +value+ is a callable object it must expect one or two arguments. Depending on the arity, the callable is invoked with the +options+ hash as first argument with +key+ as <tt>:root</tt>, and +key+ singularized as second argument. Its return value becomes a new node.
+* If +value+ is a callable object it must expect one or two arguments. Depending on the arity, the callable is invoked with the +options+ hash as first argument with +key+ as `:root`, and +key+ singularized as second argument. Its return value becomes a new node.
-* If +value+ responds to +to_xml+ the method is invoked with +key+ as <tt>:root</tt>.
+* If +value+ responds to +to_xml+ the method is invoked with +key+ as `:root`.
-* Otherwise, a node with +key+ as tag is created with a string representation of +value+ as text node. If +value+ is +nil+ an attribute "nil" set to "true" is added. Unless the option <tt>:skip_types</tt> exists and is true, an attribute "type" is added as well according to the following mapping:
+* Otherwise, a node with +key+ as tag is created with a string representation of +value+ as text node. If +value+ is +nil+ an attribute "nil" set to "true" is added. Unless the option `:skip_types` exists and is true, an attribute "type" is added as well according to the following mapping:
```ruby
XML_TYPE_NAMES = {
@@ -2545,9 +2545,9 @@ XML_TYPE_NAMES = {
}
```
-By default the root node is "hash", but that's configurable via the <tt>:root</tt> option.
+By default the root node is "hash", but that's configurable via the `:root` option.
-The default XML builder is a fresh instance of <tt>Builder::XmlMarkup</tt>. You can configure your own builder with the <tt>:builder</tt> option. The method also accepts options like <tt>:dasherize</tt> and friends, they are forwarded to the builder.
+The default XML builder is a fresh instance of `Builder::XmlMarkup`. You can configure your own builder with the `:builder` option. The method also accepts options like `:dasherize` and friends, they are forwarded to the builder.
NOTE: Defined in +active_support/core_ext/hash/conversions.rb+.