提交 2c8938fc 编写于 作者: V Vijay Dev

fixed inject example and some minor edits

上级 bb707cf7
......@@ -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)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册