summaryrefslogtreecommitdiffhomepage
path: root/ruby.html.markdown
diff options
context:
space:
mode:
authorRahil Momin <rahil.rules.you@gmail.com>2015-03-19 15:38:16 +0530
committerRahil Momin <rahil.rules.you@gmail.com>2015-03-19 15:38:16 +0530
commit37c00223d013da83d847767fbab6a3c4f960ad1a (patch)
treeabe53ceda1a99e2a018842088b5c2708d674b7a5 /ruby.html.markdown
parent1b1d10e2d9b7493039382f0f6020e82d317d0c52 (diff)
add has_key? and has_value? methods on hashes
Diffstat (limited to 'ruby.html.markdown')
-rw-r--r--ruby.html.markdown4
1 files changed, 4 insertions, 0 deletions
diff --git a/ruby.html.markdown b/ruby.html.markdown
index 800f0445..8c9d8fc5 100644
--- a/ruby.html.markdown
+++ b/ruby.html.markdown
@@ -191,6 +191,10 @@ new_hash = { defcon: 3, action: true }
new_hash.keys #=> [:defcon, :action]
+# Check existence of keys and values in hash
+new_hash.has_key?(:defcon) #=> true
+new_hash.has_value?(3) #=> true
+
# Tip: Both Arrays and Hashes are Enumerable
# They share a lot of useful methods such as each, map, count, and more