diff options
author | Vijay Dev <vijaydev.cse@gmail.com> | 2010-12-24 00:03:51 +0530 |
---|---|---|
committer | Vijay Dev <vijaydev.cse@gmail.com> | 2010-12-24 00:03:51 +0530 |
commit | 2c8938fcba6670f2cb056ec91d631ae0e37ea006 (patch) | |
tree | b0c9e07eb59045ce2973e18c433f7b4e7ed8a5c1 /railties/guides | |
parent | bb707cf7373586952d95bf574cfdeb2dbac29ea2 (diff) | |
download | rails-2c8938fcba6670f2cb056ec91d631ae0e37ea006.tar.gz rails-2c8938fcba6670f2cb056ec91d631ae0e37ea006.tar.bz2 rails-2c8938fcba6670f2cb056ec91d631ae0e37ea006.zip |
fixed inject example and some minor edits
Diffstat (limited to 'railties/guides')
-rw-r--r-- | railties/guides/source/active_support_core_extensions.textile | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/railties/guides/source/active_support_core_extensions.textile b/railties/guides/source/active_support_core_extensions.textile index bddff1c987..8821a6e461 100644 --- a/railties/guides/source/active_support_core_extensions.textile +++ b/railties/guides/source/active_support_core_extensions.textile @@ -1568,7 +1568,7 @@ The method +tableize+ is +underscore+ followed by +pluralize+. "InvoiceLine".tableize # => "invoice_lines" </ruby> -As a rule of thumb, +tableize+ returns the table name that corresponds to a given model for simple cases. The actual implementation in Active Record is not straight +tableize+ indeed, because it also demodulizes de class name and checks a few options that may affect the returned string. +As a rule of thumb, +tableize+ returns the table name that corresponds to a given model for simple cases. The actual implementation in Active Record is not straight +tableize+ indeed, because it also demodulizes the class name and checks a few options that may affect the returned string. NOTE: Defined in +active_support/core_ext/string/inflections.rb+. @@ -1868,7 +1868,7 @@ The sum of an empty collection is zero by default, but this is customizable: [].sum(1) # => 1 </ruby> -If a block is given +sum+ becomes an iterator that yields the elements of the collection and sums the returned values: +If a block is given, +sum+ becomes an iterator that yields the elements of the collection and sums the returned values: <ruby> (1..5).sum {|n| n * 2 } # => 30 @@ -1896,8 +1896,8 @@ h4. +each_with_object+ The +inject+ method offers iteration with an accumulator: <ruby> -[2, 3, 4].inject(1) {|acc, i| product*i } # => 24 -</ruby> +[2, 3, 4].inject(1) {|product, i| product*i } # => 24 +</rubyproduct The block is expected to return the value for the accumulator in the next iteration, and this makes building mutable objects a bit cumbersome: @@ -1942,7 +1942,7 @@ The method +many?+ is shorthand for +collection.size > 1+: <% end %> </erb> -If an optional block is given +many?+ only takes into account those elements that return true: +If an optional block is given, +many?+ only takes into account those elements that return true: <ruby> @see_more = videos.many? {|video| video.category == params[:category]} @@ -1952,7 +1952,7 @@ NOTE: Defined in +active_support/core_ext/enumerable.rb+. h4. +exclude?+ -The predicate +exclude?+ tests whether a given object does *not* belong to the collection. It is the negation of the builtin +include?+: +The predicate +exclude?+ tests whether a given object does *not* belong to the collection. It is the negation of the built-in +include?+: <ruby> to_visit << node if visited.exclude?(node) |