From 1b1d10e2d9b7493039382f0f6020e82d317d0c52 Mon Sep 17 00:00:00 2001 From: Rahil Momin Date: Thu, 19 Mar 2015 15:37:42 +0530 Subject: add include? method on arrays --- ruby.html.markdown | 3 +++ 1 file changed, 3 insertions(+) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index 1883d1ad..800f0445 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -169,6 +169,9 @@ array[1..3] #=> [2, 3, 4] # Add to an array like this array << 6 #=> [1, 2, 3, 4, 5, 6] +# Check if an item exists in an array +array.include?(1) #=> true + # Hashes are Ruby's primary dictionary with keys/value pairs. # Hashes are denoted with curly braces: hash = { 'color' => 'green', 'number' => 5 } -- cgit v1.2.3 From 37c00223d013da83d847767fbab6a3c4f960ad1a Mon Sep 17 00:00:00 2001 From: Rahil Momin Date: Thu, 19 Mar 2015 15:38:16 +0530 Subject: add has_key? and has_value? methods on hashes --- ruby.html.markdown | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'ruby.html.markdown') 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 -- cgit v1.2.3 From 1246edea3f83063b24c97240a10246025831843d Mon Sep 17 00:00:00 2001 From: Rahil Momin Date: Thu, 19 Mar 2015 15:38:27 +0530 Subject: add to ruby contributors --- ruby.html.markdown | 1 + 1 file changed, 1 insertion(+) (limited to 'ruby.html.markdown') diff --git a/ruby.html.markdown b/ruby.html.markdown index 8c9d8fc5..792c9c95 100644 --- a/ruby.html.markdown +++ b/ruby.html.markdown @@ -11,6 +11,7 @@ contributors: - ["Ariel Krakowski", "http://www.learneroo.com"] - ["Dzianis Dashkevich", "https://github.com/dskecse"] - ["Levi Bostian", "https://github.com/levibostian"] + - ["Rahil Momin", "https://github.com/iamrahil"] --- -- cgit v1.2.3