1
0
Fork 0
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:
Mark Lee 2016-05-24 15:40:45 -07:00
parent 3ac9956bfc
commit be1b716d77

View file

@ -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