aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorRishi Jain <rishi@joshsoftware.com>2014-11-07 00:09:52 +0530
committerRishi Jain <rishi@joshsoftware.com>2014-11-07 00:09:52 +0530
commitc0357d789b4323da64f1f9f82fa720ec9bac17cf (patch)
treeed8aa763ab9b7aeca9e9853df367be035e1b1741 /activesupport/lib/active_support
parent300c96ce158a6ebd3a83b057a8cdf2d29de0fe9d (diff)
downloadrails-c0357d789b4323da64f1f9f82fa720ec9bac17cf.tar.gz
rails-c0357d789b4323da64f1f9f82fa720ec9bac17cf.tar.bz2
rails-c0357d789b4323da64f1f9f82fa720ec9bac17cf.zip
added example of hash#except, and removed extra whitespaces [ci skip]
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/core_ext/hash/compact.rb6
-rw-r--r--activesupport/lib/active_support/core_ext/hash/except.rb10
2 files changed, 11 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/core_ext/hash/compact.rb b/activesupport/lib/active_support/core_ext/hash/compact.rb
index 6566215a4d..5dc9a05ec7 100644
--- a/activesupport/lib/active_support/core_ext/hash/compact.rb
+++ b/activesupport/lib/active_support/core_ext/hash/compact.rb
@@ -1,6 +1,6 @@
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}
@@ -8,9 +8,9 @@ class Hash
def compact
self.select { |_, value| !value.nil? }
end
-
+
# 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}
diff --git a/activesupport/lib/active_support/core_ext/hash/except.rb b/activesupport/lib/active_support/core_ext/hash/except.rb
index 682d089881..6e397abf51 100644
--- a/activesupport/lib/active_support/core_ext/hash/except.rb
+++ b/activesupport/lib/active_support/core_ext/hash/except.rb
@@ -1,13 +1,19 @@
class Hash
- # Returns a hash that includes everything but the given keys. This is useful for
- # limiting a set of parameters to everything but a few known toggles:
+ # Returns a hash that includes everything but the given keys.
+ # hash = { a: true, b: false, c: nil}
+ # hash.except(:c) # => { a: true, b: false}
+ # hash # => { a: true, b: false, c: nil}
#
+ # This is useful for limiting a set of parameters to everything but a few known toggles:
# @person.update(params[:person].except(:admin))
def except(*keys)
dup.except!(*keys)
end
# Replaces the hash without the given keys.
+ # hash = { a: true, b: false, c: nil}
+ # hash.except!(:c) # => { a: true, b: false}
+ # hash # => { a: true, b: false }
def except!(*keys)
keys.each { |key| delete(key) }
self