From 6efba3485e7444c8c63c9a8c2f0cbf88c22fda6c Mon Sep 17 00:00:00 2001 From: Shalini Roy Date: Thu, 12 Dec 2024 05:28:59 -0800 Subject: [PATCH 1/2] Set operations --- ruby.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ruby.md b/ruby.md index c8ba6f42..9cec8e3f 100644 --- a/ruby.md +++ b/ruby.md @@ -55,6 +55,12 @@ a multi-line comment with the # character. 3 | 5 #=> 7 3 ^ 5 #=> 6 +# Overload bitwise operators to perform +# set operations +[1,2] & [2,3,4] #=> [2] +[1,2] | [2,3,4] #=> [1,2,3,4] +[1,2] ^ [2,3,4] #=> [1,3,4] + # Arithmetic is just syntactic sugar # for calling a method on an object 1.+(3) #=> 4 From a51eb67742cc4aaf7ae1d51b24df3e899fe5989c Mon Sep 17 00:00:00 2001 From: Shalini Roy Date: Thu, 12 Dec 2024 05:29:23 -0800 Subject: [PATCH 2/2] Introduce inspect --- ruby.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ruby.md b/ruby.md index 9cec8e3f..947f5243 100644 --- a/ruby.md +++ b/ruby.md @@ -558,6 +558,9 @@ dwight.name #=> "Dwight K. Schrute" # Calling of a class method Human.say('Hi') #=> "Hi" +# Tip: Use .inspect to see instance with instance variables +puts jim.inspect #=> # + # Variable's scopes are defined by the way we name them. # Variables that start with $ have global scope. $var = "I'm a global var"