1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Ensure codeblocks are rendered as such for (min|max)imum

Make indentation consistent for all codeblocks in file.

[ci-skip]
This commit is contained in:
Gert Goet 2022-01-07 12:21:03 +01:00
parent 2b05b25809
commit 53ede786fc

View file

@ -22,16 +22,16 @@ module Enumerable
# Calculates the minimum from the extracted elements. # Calculates the minimum from the extracted elements.
# #
# payments = [Payment.new(5), Payment.new(15), Payment.new(10)] # payments = [Payment.new(5), Payment.new(15), Payment.new(10)]
# payments.minimum(:price) # => 5 # payments.minimum(:price) # => 5
def minimum(key) def minimum(key)
map(&key).min map(&key).min
end end
# Calculates the maximum from the extracted elements. # Calculates the maximum from the extracted elements.
# #
# payments = [Payment.new(5), Payment.new(15), Payment.new(10)] # payments = [Payment.new(5), Payment.new(15), Payment.new(10)]
# payments.maximum(:price) # => 15 # payments.maximum(:price) # => 15
def maximum(key) def maximum(key)
map(&key).max map(&key).max
end end
@ -47,13 +47,13 @@ module Enumerable
# #
# It can also calculate the sum without the use of a block. # It can also calculate the sum without the use of a block.
# #
# [5, 15, 10].sum # => 30 # [5, 15, 10].sum # => 30
# ['foo', 'bar'].sum('') # => "foobar" # ['foo', 'bar'].sum('') # => "foobar"
# [[1, 2], [3, 1, 5]].sum([]) # => [1, 2, 3, 1, 5] # [[1, 2], [3, 1, 5]].sum([]) # => [1, 2, 3, 1, 5]
# #
# The default sum of an empty list is zero. You can override this default: # The default sum of an empty list is zero. You can override this default:
# #
# [].sum(Payment.new(0)) { |i| i.amount } # => Payment.new(0) # [].sum(Payment.new(0)) { |i| i.amount } # => Payment.new(0)
def sum(identity = nil, &block) def sum(identity = nil, &block)
if identity if identity
_original_sum_with_required_identity(identity, &block) _original_sum_with_required_identity(identity, &block)
@ -205,16 +205,16 @@ module Enumerable
# Returns a new +Array+ without the blank items. # Returns a new +Array+ without the blank items.
# Uses Object#blank? for determining if an item is blank. # Uses Object#blank? for determining if an item is blank.
# #
# [1, "", nil, 2, " ", [], {}, false, true].compact_blank # [1, "", nil, 2, " ", [], {}, false, true].compact_blank
# # => [1, 2, true] # # => [1, 2, true]
# #
# Set.new([nil, "", 1, 2]) # Set.new([nil, "", 1, 2])
# # => [2, 1] (or [1, 2]) # # => [2, 1] (or [1, 2])
# #
# When called on a +Hash+, returns a new +Hash+ without the blank values. # When called on a +Hash+, returns a new +Hash+ without the blank values.
# #
# { a: "", b: 1, c: nil, d: [], e: false, f: true }.compact_blank # { a: "", b: 1, c: nil, d: [], e: false, f: true }.compact_blank
# #=> { b: 1, f: true } # # => { b: 1, f: true }
def compact_blank def compact_blank
reject(&:blank?) reject(&:blank?)
end end
@ -223,7 +223,7 @@ module Enumerable
# objects in the original enumerable. # objects in the original enumerable.
# #
# [ Person.find(5), Person.find(3), Person.find(1) ].in_order_of(:id, [ 1, 5, 3 ]) # [ Person.find(5), Person.find(3), Person.find(1) ].in_order_of(:id, [ 1, 5, 3 ])
# => [ Person.find(1), Person.find(5), Person.find(3) ] # # => [ Person.find(1), Person.find(5), Person.find(3) ]
# #
# If the +series+ include keys that have no corresponding element in the Enumerable, these are ignored. # If the +series+ include keys that have no corresponding element in the Enumerable, these are ignored.
# If the Enumerable has additional elements that aren't named in the +series+, these are not included in the result. # If the Enumerable has additional elements that aren't named in the +series+, these are not included in the result.
@ -234,9 +234,9 @@ module Enumerable
# Returns the sole item in the enumerable. If there are no items, or more # Returns the sole item in the enumerable. If there are no items, or more
# than one item, raises +Enumerable::SoleItemExpectedError+. # than one item, raises +Enumerable::SoleItemExpectedError+.
# #
# ["x"].sole # => "x" # ["x"].sole # => "x"
# Set.new.sole # => Enumerable::SoleItemExpectedError: no item found # Set.new.sole # => Enumerable::SoleItemExpectedError: no item found
# { a: 1, b: 2 }.sole # => Enumerable::SoleItemExpectedError: multiple items found # { a: 1, b: 2 }.sole # => Enumerable::SoleItemExpectedError: multiple items found
def sole def sole
case count case count
when 1 then return first # rubocop:disable Style/RedundantReturn when 1 then return first # rubocop:disable Style/RedundantReturn
@ -255,9 +255,9 @@ class Hash
# Removes all blank values from the +Hash+ in place and returns self. # Removes all blank values from the +Hash+ in place and returns self.
# Uses Object#blank? for determining if a value is blank. # Uses Object#blank? for determining if a value is blank.
# #
# h = { a: "", b: 1, c: nil, d: [], e: false, f: true } # h = { a: "", b: 1, c: nil, d: [], e: false, f: true }
# h.compact_blank! # h.compact_blank!
# # => { b: 1, f: true } # # => { b: 1, f: true }
def compact_blank! def compact_blank!
# use delete_if rather than reject! because it always returns self even if nothing changed # use delete_if rather than reject! because it always returns self even if nothing changed
delete_if { |_k, v| v.blank? } delete_if { |_k, v| v.blank? }
@ -302,9 +302,9 @@ class Array # :nodoc:
# Removes all blank elements from the +Array+ in place and returns self. # Removes all blank elements from the +Array+ in place and returns self.
# Uses Object#blank? for determining if an item is blank. # Uses Object#blank? for determining if an item is blank.
# #
# a = [1, "", nil, 2, " ", [], {}, false, true] # a = [1, "", nil, 2, " ", [], {}, false, true]
# a.compact_blank! # a.compact_blank!
# # => [1, 2, true] # # => [1, 2, true]
def compact_blank! def compact_blank!
# use delete_if rather than reject! because it always returns self even if nothing changed # use delete_if rather than reject! because it always returns self even if nothing changed
delete_if(&:blank?) delete_if(&:blank?)