mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #25134 from malept/consistent-hash-examples
Normalize whitespace for Hash#compact documentation
This commit is contained in:
commit
bf219714dc
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