<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Lakhan Jindam</title>
    <description>The latest articles on DEV Community by Lakhan Jindam (@iamlucky).</description>
    <link>https://dev.to/iamlucky</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F512987%2Fcc084e4a-8baa-4ee9-9f3e-579559bdec4a.jpg</url>
      <title>DEV Community: Lakhan Jindam</title>
      <link>https://dev.to/iamlucky</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/iamlucky"/>
    <language>en</language>
    <item>
      <title>My CKAD experience - 2023</title>
      <dc:creator>Lakhan Jindam</dc:creator>
      <pubDate>Sun, 26 Mar 2023 13:12:58 +0000</pubDate>
      <link>https://dev.to/iamlucky/my-ckad-experience-2023-32h3</link>
      <guid>https://dev.to/iamlucky/my-ckad-experience-2023-32h3</guid>
      <description>&lt;p&gt;I have passed my CKAD certification, and here is my &lt;a href="https://www.credly.com/badges/a0899223-376a-4628-ae47-e62d946f72b7/public_url"&gt;CKAD badge&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Choose to Take the CKAD Exam?
&lt;/h2&gt;

&lt;p&gt;I think it's an important question one should ask before opting in to any exam, not only CKAD. In what way will it benefit you in your career growth?&lt;/p&gt;

&lt;p&gt;My reason for taking the CKAD exam is that I was already working on Kubernetes and digging more into it. I stumbled upon this exam, which was recommended by my colleagues, and it felt interesting and different from other exams where I could actually showcase my skills without any kind of separate preparation.&lt;/p&gt;

&lt;p&gt;Unlike other exams, this one is different. How is it different?&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It's a performance-based exam where you need to perform tasks inside a VM on a Linux terminal with access to only certain URLs in a browser.&lt;/li&gt;
&lt;li&gt;It doesn't contain any MCQ type questions similar to AWS certs. All questions are practical, and you need to implement them.&lt;/li&gt;
&lt;li&gt;It tests your critical thinking ability. Time is a big constraint here, and questions are decent, but how quickly you understand and respond (terminal skills 🪄) is the key. There might be multiple ways to solve the questions, but you need to solve them in fewer steps. Hence, adopt an imperative way (using k8s commands) to solve questions if applicable.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When I researched the CKAD exam and joined some communities, I learned that the exam is taken by two types of individuals:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Individual X, who are familiar with k8s and are currently using it and also have better hands-on experience on the terminal (Linux/Unix).&lt;/li&gt;
&lt;li&gt;Individual Y, who have limited knowledge of k8s but are interested in learning and then eventually take the exam.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For individual X, CKAD exam preparation should not take more than 3 weeks - Why?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;They are already using k8s (i.e., familiar with k8s architecture and kubectl commands) and are good with the terminal (vim, bash, Linux commands, etc.). These are the only skills required to pass the CKAD exam, frankly speaking :)&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, the point is, if you are an individual X, don't try to over-prepare just because you see people preparing extensively for it. Most of them are type Y, and you have already been preparing for it every day 😁 - This is what I felt, and it stood correct after giving my exam.&lt;/p&gt;

&lt;p&gt;If you are an individual Y who wants to learn and prepare for the CKAD exam, enrolling in the &lt;code&gt;KodeKloud&lt;/code&gt; course by &lt;code&gt;Mumshad Mannambeth&lt;/code&gt; is a great choice. Personally, I follow this person and his YouTube channel, and I can confidently say that his course is better than any other you will find. You can access the course at &lt;a href="https://kodekloud.com/courses/certified-kubernetes-application-developer-ckad/"&gt;https://kodekloud.com/courses/certified-kubernetes-application-developer-ckad/&lt;/a&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;PS: I have not taken the above CKAD course since I didn't feel it was required for me, but yes, if anyone wants to, it's worth it!!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Before starting anything, just take a look inside CKAD syllabus and its topics so that you can prepare properly → &lt;a href="https://training.linuxfoundation.org/certification/certified-kubernetes-application-developer-ckad/"&gt;https://training.linuxfoundation.org/certification/certified-kubernetes-application-developer-ckad/&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The above page will provide you with answers to "why you should take CKAD" and "who should take CKAD," which are important :)&lt;/li&gt;
&lt;li&gt;Check out the &lt;strong&gt;Domains &amp;amp; Competencies&lt;/strong&gt; section for topic-wise weightage.&lt;/li&gt;
&lt;li&gt;Also, please refer to the &lt;strong&gt;Exam Tips&lt;/strong&gt; and &lt;strong&gt;FAQs&lt;/strong&gt; section under &lt;strong&gt;Exam Details &amp;amp; Resources&lt;/strong&gt;, which will give you an overview of how your exam will be held online and what the prerequisites are before starting your exam.&lt;/li&gt;
&lt;li&gt;I would have loved to summarize the details, but things keep changing around the exam 😅, so it's better to always refer to the actual documentation and resources, which is what I did.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Changes from Last Year - 2022
&lt;/h2&gt;

&lt;p&gt;So, there have been a few changes around the exam environment.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Exam changed from terminal to PSI bridge secure browser, which provides VNC connection to your remote Ubuntu XFCE desktop interface aka your playground.
What actually changed for you?

&lt;ul&gt;
&lt;li&gt;Well, you cannot use your personal bookmarks that most of the people curated for k8s exam.&lt;/li&gt;
&lt;li&gt;No dual monitor setup allowed (Major one for me!)
&lt;img src="https://i.giphy.com/media/U4VXRfcY3zxTi/giphy.gif" width="320" height="240"&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Also, along with new Kubernetes version releases, the exam is updated to use the latest version. (I gave my exam on k8s version v1.26).&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To test the new remote desktop UI, you can try this &lt;a href="https://killercoda.com/kimwuestkamp/scenario/cks-cka-ckad-remote-desktop"&gt;killercoda playground&lt;/a&gt;. I was using it most of the time to get used to the exam-like environment for solving questions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources That I Have Referred to for Practicing CKAD Exam
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://github.com/dgkanatsios/CKAD-exercises"&gt;https://github.com/dgkanatsios/CKAD-exercises&lt;/a&gt; - This is one of the popular resources and will cover all aspects of CKAD syllabus. Practicing 2-3 times will make you confident!&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/bmuschko/ckad-crash-course#additional-resources"&gt;https://github.com/bmuschko/ckad-crash-course#additional-resources&lt;/a&gt; - In case you want more overview or practice a different set of questions, you can refer to this one too.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;🚨 Lastly, don't forget that you get 2 free sessions on &lt;a href="http://killer.sh/"&gt;killer.sh&lt;/a&gt; when you purchase CKAD exam from CNCF. It sets an environment similar to a real CKAD exam, but questions are tougher than CKAD exam, which will prepare you in the right way (You can claim that from your Linux foundation portal.)&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;One thing to note for killer.sh is questions will be very much the same for CKAD|CKA|CKS simulator irrespective of different sessions.&lt;br&gt;
Source: &lt;a href="https://killer.sh/faq"&gt;https://killer.sh/faq&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If this truly is the case, then it is missing questions on some topics below.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Deprecated API versions&lt;/li&gt;
&lt;li&gt;Admission controller&lt;/li&gt;
&lt;li&gt;RBAC&lt;/li&gt;
&lt;li&gt;Ingress&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Due to which real exam was actually a bit tough than &lt;a href="http://killer.sh/"&gt;killer.sh&lt;/a&gt; exam since I got questions from above topics.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/3ohjV5uukLAvnhS7vy/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/3ohjV5uukLAvnhS7vy/giphy.gif" width="480" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Exam Experience
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Before Attending Exam
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;There will be an inspection of your place where you intend to give CKAD exam, so remove anything that categorizes as a non-decorative item like a notebook, phone, tablet, etc.&lt;/li&gt;
&lt;li&gt;Make sure you check your rig is compatible with PSI bridge standards - Run your test here &lt;a href="https://syscheck.bridge.psiexams.com/"&gt;https://syscheck.bridge.psiexams.com/&lt;/a&gt; (source: &lt;a href="https://docs.linuxfoundation.org/tc-docs/certification/tips-cka-and-ckad"&gt;https://docs.linuxfoundation.org/tc-docs/certification/tips-cka-and-ckad&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;Be ready with your government IDs or passport for your verification.&lt;/li&gt;
&lt;li&gt;No one needs to be there in the room where you are giving the exam; otherwise, the supervisor might not allow you to give the exam.&lt;/li&gt;
&lt;li&gt;Internet connection should be good; otherwise, it can be a laggy experience and can cause connection retries in-between. Keep your mobile data hotspot handy in case your WIFI is down.&lt;/li&gt;
&lt;li&gt;Lastly, if you are using an external monitor with a laptop setup, make sure your laptop lid is closed; otherwise, the exam environment will detect it, and you cannot proceed unless you close it.

&lt;ol&gt;
&lt;li&gt;And you need an external webcam in this case, make sure your webcam quality is good enough to show a clear face of yours and government IDs aka verification proof docs.&lt;/li&gt;
&lt;/ol&gt;


&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For me, point 5 didn't go as expected. I was prepared and planned to give the exam with an external monitor with an external webcam, but my webcam quality was grainy inside the exam environment due to which my verification docs (you need to show it to your camera) and face were not coming clear. Hence, the supervisor told me to change the setup immediately 💔 😔&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;PS: switched to my laptop camera, and it went fine. Still not sure if it's the exam environment throttling the quality of the webcam since my webcam is a 1080p FHD.&lt;br&gt;
For folks interested/curious, I am using this &lt;a href="https://amzn.eu/d/01CjVnm"&gt;webcam&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h3&gt;
  
  
  During Exam
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/kz6cm1kKle2MYkHtJF/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/kz6cm1kKle2MYkHtJF/giphy.gif" width="480" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;My exam started well with no issues or lag inside the virtual machine, but in-between of my exam, my remote desktop froze, and it was not taking any inputs.&lt;/li&gt;
&lt;li&gt;What I did was quickly clicked on &lt;code&gt;reset desktop&lt;/code&gt;, which actually will restart your VM (your data is persistent, so chill!) but only concern is my crucial time was draining since the timer is on 💣 - After 2 rounds (in the 1st round, it was still stuck, didn't work) of clicking &lt;code&gt;reset desktop&lt;/code&gt;, it started to work 😌 but then I was a little bit behind my planned schedule.&lt;/li&gt;
&lt;li&gt;The supervisor is continuously monitoring everything - audio, video, screen sharing and make sure you don't cover your face, whisper, or do any kind of actions else a ping from the supervisor will pop up to ruin your focus mode 🙂 (I got some pings 🔔 for external sounds and actions)&lt;/li&gt;
&lt;li&gt;A simple but important thing, make sure you are switching to the current context and namespaces for each question. In case you didn't, even if you solved the question correctly, you lose marks 🙀&lt;/li&gt;
&lt;li&gt;Some questions on which my confidence was a bit low summoned to trouble me like Ingress, RBAC, Service Accounts. Apart from these topics, I was prepared for everything, but finally, I was able to partially solve questions on those topics (sigh…)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;To clear the CKAD exam with more than 80 or 90 percent, it is important to be proficient with all the tips, tricks, and commands that you have learned, and to practice a lot around each topic.&lt;/p&gt;

&lt;p&gt;You don't need to have fast typing speed. Instead, type steadily with decent speed and use command aliases for &lt;code&gt;kubectl&lt;/code&gt;, which will save time.&lt;/p&gt;

&lt;p&gt;Despite a few setbacks, the overall experience of taking the exam was good, especially since it was my first certification exam.&lt;/p&gt;

&lt;p&gt;Best of luck 🍀 to those who are planning and preparing for the CKAD exam!&lt;/p&gt;

&lt;p&gt;Also, please share your interesting experiences in the comments section. 😈&lt;br&gt;
&lt;a href="https://i.giphy.com/media/ntl8yJ3ctzYHdJPm02/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/ntl8yJ3ctzYHdJPm02/giphy.gif" width="480" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>devops</category>
      <category>kubernetes</category>
      <category>cloud</category>
      <category>cncf</category>
    </item>
    <item>
      <title>Ruby cheatsheet for beginners</title>
      <dc:creator>Lakhan Jindam</dc:creator>
      <pubDate>Tue, 06 Apr 2021 15:09:44 +0000</pubDate>
      <link>https://dev.to/iamlucky/ruby-cheatsheet-for-beginners-4ipo</link>
      <guid>https://dev.to/iamlucky/ruby-cheatsheet-for-beginners-4ipo</guid>
      <description>&lt;h5&gt;
  
  
  Introduction to ruby:
&lt;/h5&gt;

&lt;p&gt;&lt;em&gt;Ruby is an interpreted, high-level, dynamic, general-purpose, open-source programming language that focuses on simplicity and productivity. It was designed and developed in the mid-1990s by Yukihiro Matsumoto (also known as Matz in the Ruby community) in Japan.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you guys have already done coding in python, it'll be a bit simpler to understand the semantics of ruby even though under the hood ruby is completely different than python.&lt;br&gt;
&lt;a href="https://i.giphy.com/media/Ln2dAW9oycjgmTpjX9/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/Ln2dAW9oycjgmTpjX9/giphy.gif"&gt;&lt;/a&gt;&lt;br&gt;
First, we will talk about the common and frequently used methods.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_s&lt;/span&gt; &lt;span class="c1"&gt;# converts to a string, returns -&amp;gt; '1'&lt;/span&gt;
&lt;span class="s2"&gt;"1"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_i&lt;/span&gt; &lt;span class="c1"&gt;# converts to integer, returns -&amp;gt; 1&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;to_a&lt;/span&gt; &lt;span class="c1"&gt;# range(..) operator can be used to create an array&lt;/span&gt;
&lt;span class="c1"&gt;# to_a method converts it to an array&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'a'&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="s1"&gt;'g'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;to_a&lt;/span&gt; &lt;span class="c1"&gt;# similarly for characters&lt;/span&gt;
&lt;span class="s2"&gt;"1.5"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_i&lt;/span&gt; &lt;span class="c1"&gt;# can you tell what will be the output? returns -&amp;gt; 1 &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default &lt;strong&gt;&lt;em&gt;to_i&lt;/em&gt;&lt;/strong&gt; method will convert any float value to an integer&lt;br&gt;
To sustain float value you can use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="s2"&gt;"1.234"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;to_f&lt;/span&gt; &lt;span class="c1"&gt;# returns -&amp;gt; 1.234&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's look at some basic arithmetic operations&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;+&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="c1"&gt;# addition, returns 3&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt; &lt;span class="c1"&gt;# multiplication, returns 10&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt; &lt;span class="c1"&gt;# returns 1&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="mf"&gt;1.22312&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;floor&lt;/span&gt; &lt;span class="c1"&gt;# rounding the value to lowest returns 1&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="mf"&gt;1.22312&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ceil&lt;/span&gt; &lt;span class="c1"&gt;# rounding the value to highest returns 2&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="mf"&gt;3.1223289&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;round&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# limiting the decimal point to 1, returns -&amp;gt; 3.1&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s1"&gt;'Hello, world!'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;include?&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Hello'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# returns boolean value, it's case sensitive!&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;include?&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# same can be applied to arrays&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="c1"&gt;# returns 0, wondering why? 🤔&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default interaction with integer values will return an integer.&lt;br&gt;
In order to return a float value do this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;2.0&lt;/span&gt; &lt;span class="c1"&gt;# add a decimal point, returns 0.5 😮&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To check the length or size of an array or string&lt;br&gt;
Both methods output the same results, prefer whichever suits you 🙃&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="s1"&gt;'ruby'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;size&lt;/span&gt; &lt;span class="c1"&gt;# returns 4&lt;/span&gt;
&lt;span class="s1"&gt;'ruby'&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;length&lt;/span&gt; &lt;span class="c1"&gt;# Similarly, returns 4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, the last one 😌&lt;br&gt;
To get user input&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"enter your name:"&lt;/span&gt;
&lt;span class="nb"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;gets&lt;/span&gt; &lt;span class="c1"&gt;# by default it adds a newline i.e \n at the end&lt;/span&gt;
&lt;span class="nb"&gt;name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;gets&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;chomp&lt;/span&gt; &lt;span class="c1"&gt;# can be used to remove \n&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enough of basic, let's hop onto topic wise cheatsheet &lt;br&gt;
&lt;a href="https://i.giphy.com/media/SWoRKslHVtqEasqYCJ/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/SWoRKslHVtqEasqYCJ/giphy.gif"&gt;&lt;/a&gt;&lt;br&gt;
Let's get started with the first topic!&lt;/p&gt;
&lt;h2&gt;
  
  
  1. Arrays
&lt;/h2&gt;
&lt;h5&gt;
  
  
  To instantiate an array in ruby there are few ways to do it.
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# method 1, the simplest and most intuitive way of declaring array!&lt;/span&gt;
&lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="c1"&gt;# method 2, using Array object&lt;/span&gt;
&lt;span class="n"&gt;array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;array1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# will create array of size 3&lt;/span&gt;
&lt;span class="n"&gt;array2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"ruby"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# ^ and will fill array with value-&amp;gt;"ruby"&lt;/span&gt;
&lt;span class="c1"&gt;# for some dynamic values, you can use below&lt;/span&gt;
&lt;span class="n"&gt;array3&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;index&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;index&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="c1"&gt;# where index-&amp;gt;index value of the array&lt;/span&gt;
&lt;span class="c1"&gt;# for multi-dimensional array you can create using below&lt;/span&gt;
&lt;span class="n"&gt;array4&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;&lt;span class="no"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt; &lt;span class="c1"&gt;# this will create array of size 3x3 and each value will be "nil"&lt;/span&gt;
&lt;span class="n"&gt;array5&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;&lt;span class="no"&gt;Array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;)}&lt;/span&gt; &lt;span class="c1"&gt;# array of size 3x3 with each value-&amp;gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h5&gt;
  
  
  Common methods used for array manipulation
&lt;/h5&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;prog_langs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"ruby"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"python"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"javascript"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"go"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;sorted_prog_langs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;prog_langs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort&lt;/span&gt; &lt;span class="c1"&gt;# returns a new array with sorted values&lt;/span&gt;
&lt;span class="c1"&gt;# If you don't want to return new array and wanna sort existing array instead &lt;/span&gt;
&lt;span class="n"&gt;prog_langs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;sort!&lt;/span&gt; &lt;span class="c1"&gt;# "!" operator here is very handy and can be used with many methods in ruby to perform in-place operation 👌&lt;/span&gt;
&lt;span class="c1"&gt;# concurrently traverse both arrays&lt;/span&gt;
&lt;span class="n"&gt;frameworks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"ruby on rails"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"django"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"react"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Martini"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;prog_langs&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;zip&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frameworks&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;each&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;lang&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;framework&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;lang&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; has framework: &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;framework&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="c1"&gt;# pop an element from an array&lt;/span&gt;
&lt;span class="c1"&gt;# by default ruby only pops element from tail of array &lt;/span&gt;
&lt;span class="c1"&gt;# unlike python you cannot pop element based on index&lt;/span&gt;
&lt;span class="n"&gt;frameworks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;pop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;# by default pops last element in array and returns popped element&lt;/span&gt;
&lt;span class="c1"&gt;# to remove element from the head of an array&lt;/span&gt;
&lt;span class="n"&gt;frameworks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shift&lt;/span&gt; &lt;span class="c1"&gt;# by defaults remove one element from head&lt;/span&gt;
&lt;span class="n"&gt;frameworks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;shift&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# removes first 2 elements, returns ["ruby on rails", "django"]&lt;/span&gt;
&lt;span class="n"&gt;frameworks&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"spring"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# appends to the array from tail&lt;/span&gt;
&lt;span class="n"&gt;frameworks&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="s2"&gt;"spring"&lt;/span&gt; &lt;span class="c1"&gt;# another alternative for push&lt;/span&gt;
&lt;span class="c1"&gt;# if arrays consists only of string types can use this format&lt;/span&gt;
&lt;span class="n"&gt;frameworks&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sx"&gt;%w[ruby_on_rails django react Martini]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  2. Strings
&lt;/h2&gt;

&lt;p&gt;Basic operations on a string which is similar to most languages&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# declare and assign a value&lt;/span&gt;
&lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'hello, world!'&lt;/span&gt;
&lt;span class="c1"&gt;# Interesting fact, all strings are mutable in ruby this will most likely will change in upcoming ruby versions&lt;/span&gt;
&lt;span class="c1"&gt;# also this assignment can be used to remove space from string&lt;/span&gt;
&lt;span class="n"&gt;string&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt; &lt;span class="c1"&gt;# each char is has an index including space, removes space from string variable&lt;/span&gt;
&lt;span class="c1"&gt;# concat string&lt;/span&gt;
&lt;span class="n"&gt;string_1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'how are you?'&lt;/span&gt;
&lt;span class="n"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;string&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;string_1&lt;/span&gt; &lt;span class="c1"&gt;# returns -&amp;gt; 'hello, world! how are you?'&lt;/span&gt;
&lt;span class="c1"&gt;# string literals or interpolation in ruby can be achieved using double quotes("")&lt;/span&gt;
&lt;span class="n"&gt;language&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"ruby"&lt;/span&gt;
&lt;span class="n"&gt;experience&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"I have &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;experience&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; years of experience in &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;language&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="c1"&gt;# interpolation can be done using same double quotes&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"I have &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;experience&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"good"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"ample"&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; amount of experience in &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;language&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="c1"&gt;# returns -&amp;gt; "I have good amount of experience in ruby"&lt;/span&gt;
&lt;span class="c1"&gt;# substitution using gsub method&lt;/span&gt;
&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"I have 3 years of experience in ruby"&lt;/span&gt;
&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;gsub!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"ruby"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"python"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# returns -&amp;gt; "I have nice amount of experience in ruby, "!" for in-place substitution"&lt;/span&gt;
&lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;gsub!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sr"&gt;/\d/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# use regex to replace, returns -&amp;gt; "I have 5 years of experience in ruby"&lt;/span&gt;
&lt;span class="c1"&gt;# downcase and upcase a string&lt;/span&gt;
&lt;span class="n"&gt;language&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;upcase!&lt;/span&gt; &lt;span class="c1"&gt;# returns -&amp;gt; 'RUBY'&lt;/span&gt;
&lt;span class="n"&gt;language&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;downcase!&lt;/span&gt; &lt;span class="c1"&gt;# reutrns -&amp;gt; 'ruby'&lt;/span&gt;
&lt;span class="c1"&gt;# to remove spaces from head and tail of string&lt;/span&gt;
&lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;" hello. "&lt;/span&gt;
&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;strip&lt;/span&gt; &lt;span class="c1"&gt;# by default space is considered, you can pass your arg&lt;/span&gt;
&lt;span class="c1"&gt;# to check if a string start with a substring&lt;/span&gt;
&lt;span class="c1"&gt;# NOTE: both are case sensitive&lt;/span&gt;
&lt;span class="n"&gt;c&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Whats your favorite programming language?"&lt;/span&gt;
&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start_with?&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Whats'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# returns -&amp;gt; true&lt;/span&gt;
&lt;span class="n"&gt;c&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;end_with?&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Language?'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# returns -&amp;gt; false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Hash
&lt;/h2&gt;

&lt;p&gt;Hash is equivalent to dictionaries in python.&lt;br&gt;
There are various ways to create a Hash in ruby.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="nb"&gt;hash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Hash&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt; &lt;span class="c1"&gt;# will create a empty hash -&amp;gt; {}&lt;/span&gt;
&lt;span class="n"&gt;hash1&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Hash&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'test'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# creates hash of default value 'test'&lt;/span&gt;
&lt;span class="n"&gt;hash2&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nb"&gt;name&lt;/span&gt;&lt;span class="ss"&gt;:'bob'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;age&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;21&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;hash2&lt;/span&gt; &lt;span class="c1"&gt;# returns -&amp;gt; {:name=&amp;gt;'bob', :age=&amp;gt;21}&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;hash1&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c1"&gt;# returns 'test', as no value is set yet&lt;/span&gt;
&lt;span class="c1"&gt;# inserting a value&lt;/span&gt;
&lt;span class="nb"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'language'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'ruby'&lt;/span&gt;
&lt;span class="nb"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'designation'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s1"&gt;'software engineer'&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="nb"&gt;hash&lt;/span&gt; &lt;span class="c1"&gt;# returns -&amp;gt; {'language'=&amp;gt;'ruby', 'designation'=&amp;gt;'software engineer'}&lt;/span&gt;
&lt;span class="c1"&gt;# to check a key is present or not&lt;/span&gt;
&lt;span class="nb"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;has_key?&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'language'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# returns true&lt;/span&gt;
&lt;span class="nb"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;key?&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'language'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# alternative to has_key?&lt;/span&gt;
&lt;span class="c1"&gt;# to delete a key&lt;/span&gt;
&lt;span class="nb"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;delete&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'language'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# returns the value of that key&lt;/span&gt;
&lt;span class="c1"&gt;# merging two hashes&lt;/span&gt;
&lt;span class="nb"&gt;hash&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;merge!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;hash2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;# merges two hashes and changes are reflected in 'hash' variable&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="nb"&gt;hash&lt;/span&gt; &lt;span class="c1"&gt;# returns -&amp;gt; {:name=&amp;gt;'bob', :age=&amp;gt;21, :language=&amp;gt;'ruby', :designation=&amp;gt;'software engineer'}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Some bonus stuff!!
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://i.giphy.com/media/2iYnVCY4v9CGk/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/2iYnVCY4v9CGk/giphy.gif"&gt;&lt;/a&gt;&lt;br&gt;
if you want to run terminal commands in ruby&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# using backticks you can execute these commands&lt;/span&gt;
&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sb"&gt;`ssh &amp;lt;user&amp;gt;@&amp;lt;IP&amp;gt; 'cd /some/dir &amp;amp;&amp;amp; cat somefile.txt'`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also if any response is of JSON type&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="c1"&gt;# In order to avoid error while parsing, always do below&lt;/span&gt;
&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="ss"&gt;:"bob"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="s2"&gt;"occupation"&lt;/span&gt;&lt;span class="ss"&gt;:"Software engineer"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="c1"&gt;# ruby will implicitly convert this into hash like below&lt;/span&gt;
&lt;span class="c1"&gt;# {:name=&amp;gt;"bob", :occupation=&amp;gt;"Software engineer"}&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c1"&gt;# returns -&amp;gt; 👎 i.e nothing&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:name&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c1"&gt;# Instead use symbols, returns "bob" &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But if you're fetching a response from a machine's logs or from an API, it might be stringified in that case you can use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'{"name":"bob","occupation":"Software engineer"}'&lt;/span&gt;
&lt;span class="c1"&gt;# When using JSON.parse it won't convert keys to symbols&lt;/span&gt;
&lt;span class="n"&gt;final_response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;final_response&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="c1"&gt;# returns "bob"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://i.giphy.com/media/l4pTjOu0NsrLApt0Q/giphy.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://i.giphy.com/media/l4pTjOu0NsrLApt0Q/giphy.gif"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
