mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Normalize whitespace for Hash#compact documentation [ci skip]
This is a similar change that occurred for Hash#except in #21087.
This commit is contained in:
parent
3ac9956bfc
commit
be1b716d77
1 changed files with 6 additions and 6 deletions
|
@ -1,9 +1,9 @@
|
|||
class Hash
|
||||
# Returns a hash with non +nil+ values.
|
||||
#
|
||||
# hash = { a: true, b: false, c: nil}
|
||||
# hash.compact # => { a: true, b: false}
|
||||
# hash # => { a: true, b: false, c: nil}
|
||||
# hash = { a: true, b: false, c: nil }
|
||||
# hash.compact # => { a: true, b: false }
|
||||
# hash # => { a: true, b: false, c: nil }
|
||||
# { c: nil }.compact # => {}
|
||||
def compact
|
||||
self.select { |_, value| !value.nil? }
|
||||
|
@ -11,9 +11,9 @@ class Hash
|
|||
|
||||
# Replaces current hash with non +nil+ values.
|
||||
#
|
||||
# hash = { a: true, b: false, c: nil}
|
||||
# hash.compact! # => { a: true, b: false}
|
||||
# hash # => { a: true, b: false}
|
||||
# hash = { a: true, b: false, c: nil }
|
||||
# hash.compact! # => { a: true, b: false }
|
||||
# hash # => { a: true, b: false }
|
||||
def compact!
|
||||
self.reject! { |_, value| value.nil? }
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue