Skip to content

Commit

Permalink
Ensure codeblocks are rendered as such for (min|max)imum
Browse files Browse the repository at this point in the history
Make indentation consistent for all codeblocks in file.

[ci-skip]
  • Loading branch information
eval committed Jan 7, 2022
1 parent 2b05b25 commit 53ede78
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions activesupport/lib/active_support/core_ext/enumerable.rb
Expand Up @@ -22,16 +22,16 @@ class SoleItemExpectedError < StandardError; end

# Calculates the minimum from the extracted elements.
#
# payments = [Payment.new(5), Payment.new(15), Payment.new(10)]
# payments.minimum(:price) # => 5
# payments = [Payment.new(5), Payment.new(15), Payment.new(10)]
# payments.minimum(:price) # => 5
def minimum(key)
map(&key).min
end

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

0 comments on commit 53ede78

Please sign in to comment.