<?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: Brandon Weygant</title>
    <description>The latest articles on DEV Community by Brandon Weygant (@bmweygant).</description>
    <link>https://dev.to/bmweygant</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%2F254813%2Fcd6342ee-6160-457f-b566-150724ef328a.jpeg</url>
      <title>DEV Community: Brandon Weygant</title>
      <link>https://dev.to/bmweygant</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bmweygant"/>
    <language>en</language>
    <item>
      <title>Ruby Arrays Part II - Iteration</title>
      <dc:creator>Brandon Weygant</dc:creator>
      <pubDate>Fri, 03 Jul 2020 19:09:06 +0000</pubDate>
      <link>https://dev.to/bmweygant/ruby-arrays-part-ii-iteration-53ac</link>
      <guid>https://dev.to/bmweygant/ruby-arrays-part-ii-iteration-53ac</guid>
      <description>&lt;h1&gt;What is Iteration?&lt;/h1&gt;

&lt;p&gt;Iteration is the repetition of a process. We've covered one form of iteration in an &lt;a href="https://dev.to/bmweygant/ruby-loops-n27"&gt;earlier lesson&lt;/a&gt;, but iteration also describes the manipulation of elements inside an array or hash. Fundamentally, there are 2 key differences between a &lt;code&gt;loop&lt;/code&gt; and an &lt;code&gt;iteration&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; A &lt;code&gt;loop&lt;/code&gt; will repeat an action a defined number of times, while an &lt;code&gt;iteration&lt;/code&gt; works with a collection of data by allowing you to operate on each individual element. &lt;br&gt;
&lt;strong&gt;2.&lt;/strong&gt; &lt;code&gt;Loops&lt;/code&gt; &lt;em&gt;require&lt;/em&gt; a user-defined ending somewhere in the method or they will break your program with an infinite loop. &lt;code&gt;Iterations&lt;/code&gt; &lt;em&gt;could&lt;/em&gt; have a user-defined end if desired, but will cease after the last element in the collection has been iterated over otherwise.&lt;/p&gt;

&lt;p&gt;You will do this &lt;em&gt;thousands&lt;/em&gt; of times as a developer, and array manipulation is one of the core skills you will need to grow as a programmer. Fortunately in Ruby, if you exclude the loop methods like &lt;code&gt;times&lt;/code&gt; &amp;amp; &lt;code&gt;while&lt;/code&gt;, there are only 2 primary iteration methods you must learn - &lt;code&gt;Each&lt;/code&gt; &amp;amp; &lt;code&gt;Map&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;How Iterators Compare to Loops&lt;/h1&gt;

&lt;p&gt;So aside from the two differences stated above, maybe you don't see the benefit to iterators and want to continue using loops. The best way to demonstrate the benefits of iterators is a direct comparison demonstration. Spoiler alert: Iterators will save you &lt;strong&gt;&lt;em&gt;a lot&lt;/em&gt;&lt;/strong&gt; of typing in the long run.&lt;/p&gt;

&lt;p&gt;The first one will use the &lt;code&gt;while&lt;/code&gt; loop:&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;nba_draft_top_10&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"LaMelo Ball"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Onyeka Okongwu"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Anthony Edwards"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Killian Hayes"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"James Wiseman"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Obi Toppin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Tyrese Haliburton"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Aleksej Pokuseveski"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Cole Anthony"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Deni Avdija"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="n"&gt;big_board&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;nba_draft_top_10&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;length&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;big_board&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;nba_draft_top_10&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is one of the top rated prospects on my board."&lt;/span&gt;
    &lt;span class="n"&gt;i&lt;/span&gt;&lt;span class="o"&gt;+=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt;LaMelo Ball is one of the top rated prospects on my board.&lt;/span&gt;
&lt;span class="c1"&gt;#Onyeka Okongwu is one of the top rated prospects on my board.&lt;/span&gt;
&lt;span class="c1"&gt;#Anthony Edwards is one of the top rated prospects on my board.&lt;/span&gt;
&lt;span class="c1"&gt;#Killian Hayes is one of the top rated prospects on my board.&lt;/span&gt;
&lt;span class="c1"&gt;#James Wiseman is one of the top rated prospects on my board.&lt;/span&gt;
&lt;span class="c1"&gt;#Obi Toppin is one of the top rated prospects on my board.&lt;/span&gt;
&lt;span class="c1"&gt;#Tyrese Haliburton is one of the top rated prospects on my board.&lt;/span&gt;
&lt;span class="c1"&gt;#Aleksej Pokuseveski is one of the top rated prospects on my board.&lt;/span&gt;
&lt;span class="c1"&gt;#Cole Anthony is one of the top rated prospects on my board.&lt;/span&gt;
&lt;span class="c1"&gt;#Deni Avdija is one of the top rated prospects on my board.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now lets see the same iteration using the &lt;code&gt;each&lt;/code&gt; iterator:&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;nba_draft_top_10&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"LaMelo Ball"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Onyeka Okongwu"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Anthony Edwards"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Killian Hayes"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"James Wiseman"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Obi Toppin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Tyrese Haliburton"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Aleksej Pokuseveski"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Cole Anthony"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Deni Avdija"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="n"&gt;nba_draft_top_10&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;prospect&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;prospect&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is one of the top rated prospects on my board."&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="c1"&gt;#=&amp;gt;LaMelo Ball is one of the top rated prospects on my board.&lt;/span&gt;
&lt;span class="c1"&gt;#Onyeka Okongwu is one of the top rated prospects on my board.&lt;/span&gt;
&lt;span class="c1"&gt;#Anthony Edwards is one of the top rated prospects on my board.&lt;/span&gt;
&lt;span class="c1"&gt;#Killian Hayes is one of the top rated prospects on my board.&lt;/span&gt;
&lt;span class="c1"&gt;#James Wiseman is one of the top rated prospects on my board.&lt;/span&gt;
&lt;span class="c1"&gt;#Obi Toppin is one of the top rated prospects on my board.&lt;/span&gt;
&lt;span class="c1"&gt;#Tyrese Haliburton is one of the top rated prospects on my board.&lt;/span&gt;
&lt;span class="c1"&gt;#Aleksej Pokuseveski is one of the top rated prospects on my board.&lt;/span&gt;
&lt;span class="c1"&gt;#Cole Anthony is one of the top rated prospects on my board.&lt;/span&gt;
&lt;span class="c1"&gt;#Deni Avdija is one of the top rated prospects on my board.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What took us 6 lines of code with a &lt;code&gt;while&lt;/code&gt; loop took &lt;em&gt;half&lt;/em&gt; that with an &lt;code&gt;each&lt;/code&gt; iterator. There are a few keys to how this happens:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; Because iterators understand array &lt;code&gt;length&lt;/code&gt; inherently, there is no need to set a variable to establish a numerical value to it (big_board).&lt;br&gt;
&lt;strong&gt;2.&lt;/strong&gt; Iterators don't need counter variables (i) or conditions (i &amp;lt; big_board) to keep track when to stop.&lt;br&gt;
&lt;strong&gt;3.&lt;/strong&gt; Because of #2, you also have no need to manually increment your counter (i+=1).&lt;br&gt;
&lt;strong&gt;4.&lt;/strong&gt; As a bonus, the block provided by the &lt;code&gt;each&lt;/code&gt; iterator provides us a more accessible and readable variable (prospect) than the &lt;code&gt;while&lt;/code&gt; loop did (nba_draft_top_10[i]).&lt;/p&gt;

&lt;p&gt;Take note that syntactically &lt;code&gt;each&lt;/code&gt; and &lt;code&gt;map&lt;/code&gt; are similar and you could switch them in the above example. So now that we've demonstrated the power behind iterators, let us break down &lt;code&gt;each&lt;/code&gt; and &lt;code&gt;map&lt;/code&gt; some more.&lt;/p&gt;

&lt;h1&gt;Each and Each's Extended Family&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;Each&lt;/code&gt; is an iterator designed to iterate through your array without mutating the original array. Let's open up an &lt;code&gt;irb&lt;/code&gt; session and see what that means:&lt;/p&gt;

&lt;p&gt;First we define the array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;irb(main):001:0&amp;gt; nba_draft_top_10 = ["LaMelo Ball", "Onyeka Okongwu", "Anthony Edwards", "Killian Hayes", "James Wiseman", "Obi Toppin", "Tyrese Haliburton", "Aleksej Pokuseveski", "Cole Anthony", "Deni Avdija"]

=&amp;gt; ["LaMelo Ball", "Onyeka Okongwu", "Anthony Edwards", "Killian Hayes", "James Wiseman", "Obi Toppin", "Tyrese Haliburton", "Aleksej Pokuseveski", "Cole Anthony", "Deni Avdija"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that the implicit return is the entire array.&lt;/p&gt;

&lt;p&gt;Now let's build our &lt;code&gt;each&lt;/code&gt; method line by line.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;irb(main):002:0&amp;gt; nba_draft_top_10.each do |prospect|
irb(main):003:1* puts "#{prospect} is going to be good value where he is picked."
irb(main):004:1&amp;gt; end
LaMelo Ball is going to be good value where he is picked.
Onyeka Okongwu is going to be good value where he is picked.
Anthony Edwards is going to be good value where he is picked.
Killian Hayes is going to be good value where he is picked.
James Wiseman is going to be good value where he is picked.
Obi Toppin is going to be good value where he is picked.
Tyrese Haliburton is going to be good value where he is picked.
Aleksej Pokuseveski is going to be good value where he is picked.
Cole Anthony is going to be good value where he is picked.
Deni Avdija is going to be good value where he is picked.

=&amp;gt; ["LaMelo Ball", "Onyeka Okongwu", "Anthony Edwards", "Killian Hayes", "James Wiseman", "Obi Toppin", "Tyrese Haliburton", "Aleksej Pokuseveski", "Cole Anthony", "Deni Avdija"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now notice how the iterator runs automatically after pressing 'enter'. But just as important, notice after the iterator finishes, it implicitly returns the &lt;em&gt;original&lt;/em&gt; array. This is the purpose of &lt;code&gt;each&lt;/code&gt;, to perform an action with a collection of data without mutating the original source.&lt;/p&gt;

&lt;p&gt;There are actually several variations of &lt;code&gt;each&lt;/code&gt; iterators like &lt;code&gt;each_with_index&lt;/code&gt;, &lt;code&gt;each_char&lt;/code&gt;, &lt;code&gt;each_with_object&lt;/code&gt; and more. I will touch on &lt;code&gt;each_with_index&lt;/code&gt;, but other &lt;code&gt;each&lt;/code&gt; methods you should consult the &lt;a href="https://www.ruby-doc.org"&gt;Ruby Docs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;each_with_index&lt;/code&gt; will do the same thing as &lt;code&gt;each&lt;/code&gt;, but takes a second argument inside the &lt;code&gt;||&lt;/code&gt; block that will give a visible numerical value to the index. So if we wanted to turn our big board into rankings instead of a general top 10, we could 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="n"&gt;nba_draft_top_10&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"LaMelo Ball"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Onyeka Okongwu"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Anthony Edwards"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Killian Hayes"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"James Wiseman"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Obi Toppin"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Tyrese Haliburton"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Aleksej Pokuseveski"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Cole Anthony"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Deni Avdija"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;


&lt;span class="n"&gt;nba_draft_top_10&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;each_with_index&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;prospect&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;index&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;"I have &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;prospect&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; rated #&lt;/span&gt;&lt;span class="si"&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;1&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; overall."&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="c1"&gt;#=&amp;gt;I have LaMelo Ball rated #1 overall.&lt;/span&gt;
&lt;span class="c1"&gt;#I have Onyeka Okongwu rated #2 overall.&lt;/span&gt;
&lt;span class="c1"&gt;#I have Anthony Edwards rated #3 overall.&lt;/span&gt;
&lt;span class="c1"&gt;#I have Killian Hayes rated #4 overall.&lt;/span&gt;
&lt;span class="c1"&gt;#I have James Wiseman rated #5 overall.&lt;/span&gt;
&lt;span class="c1"&gt;#I have Obi Toppin rated #6 overall.&lt;/span&gt;
&lt;span class="c1"&gt;#I have Tyrese Haliburton rated #7 overall.&lt;/span&gt;
&lt;span class="c1"&gt;#I have Aleksej Pokuseveski rated #8 overall.&lt;/span&gt;
&lt;span class="c1"&gt;#I have Cole Anthony rated #9 overall.&lt;/span&gt;
&lt;span class="c1"&gt;#I have Deni Avdija rated #10 overall.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So in essence, the second argument in the block effectively substitutes for a counter variable &amp;amp; incrementer. &lt;/p&gt;

&lt;p&gt;Also, James Wiseman is probably lower on my big board. I value Onyeka Okongwu's defensive versatility over Wiseman's more likely gaudy stats and think most others here will have a more well-rounded game.&lt;/p&gt;

&lt;h1&gt;Map &amp;amp; it's Perhaps Evil Twin Collect&lt;/h1&gt;

&lt;p&gt;So I know I mentioned there were 2 primary iterators, then snuck in that &lt;code&gt;each&lt;/code&gt; has an extended family, but now I'm also adding a potentially evil twin? Yup, but I am exaggerating on the evil part. &lt;code&gt;Map&lt;/code&gt; and &lt;code&gt;collect&lt;/code&gt; are different names for basically doing the same thing: iterating through a collection and &lt;em&gt;mutating&lt;/em&gt; that collection. I singled out &lt;code&gt;collect&lt;/code&gt; as the evil twin for 2 reasons:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; &lt;code&gt;Map&lt;/code&gt;is a more universal term for this action and is used in many programming languages.&lt;br&gt;
&lt;strong&gt;2.&lt;/strong&gt; &lt;code&gt;Collect&lt;/code&gt; has more letters in it.&lt;/p&gt;

&lt;p&gt;So let's open up a new irb session and use the same function we used with &lt;code&gt;each&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;irb(main):001:0&amp;gt; nba_draft_top_10 = ["LaMelo Ball", "Onyeka Okongwu", "Anthony Edwards", "Killian Hayes", "James Wiseman", "Obi Toppin", "Tyrese Haliburton", "Aleksej Pokuseveski", "Cole Anthony", "Deni Avdija"]

=&amp;gt; ["LaMelo Ball", "Onyeka Okongwu", "Anthony Edwards", "Killian Hayes", "James Wiseman", "Obi Toppin", "Tyrese Haliburton", "Aleksej Pokuseveski", "Cole Anthony", "Deni Avdija"]
irb(main):002:0&amp;gt; nba_draft_top_10.map do |prospect|
irb(main):003:1* puts "#{prospect} is going to be good value where he is picked."
irb(main):004:1&amp;gt; end
LaMelo Ball is going to be good value where he is picked.
Onyeka Okongwu is going to be good value where he is picked.
Anthony Edwards is going to be good value where he is picked.
Killian Hayes is going to be good value where he is picked.
James Wiseman is going to be good value where he is picked.
Obi Toppin is going to be good value where he is picked.
Tyrese Haliburton is going to be good value where he is picked.
Aleksej Pokuseveski is going to be good value where he is picked.
Cole Anthony is going to be good value where he is picked.
Deni Avdija is going to be good value where he is picked.

=&amp;gt; [nil, nil, nil, nil, nil, nil, nil, nil, nil, nil]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check out the implicit return. See how we are now returning &lt;code&gt;nil&lt;/code&gt; where we used to return prospect names? Well, it returns &lt;code&gt;nil&lt;/code&gt; due to a combination of &lt;code&gt;map&lt;/code&gt; mutating the array and &lt;code&gt;puts&lt;/code&gt; is inherently &lt;code&gt;nil&lt;/code&gt;. If we want to see the changes reflected, we just have to remove the &lt;code&gt;puts&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;irb(main):005:0&amp;gt; nba_draft_top_10.map do |prospect|
irb(main):006:1* "#{prospect} is going to be good value where he is picked."
irb(main):007:1&amp;gt; end
=&amp;gt; ["LaMelo Ball is going to be good value where he is picked.", "Onyeka Okongwu is going to be good value where he is picked.", "Anthony Edwards is going to be good value where he is picked.", "Killian Hayes is going to be good value where he is picked.", "James Wiseman is going to be good value where he is picked.", "Obi Toppin is going to be good value where he is picked.", "Tyrese Haliburton is going to be good value where he is picked.", "Aleksej Pokuseveski is going to be good value where he is picked.", "Cole Anthony is going to be good value where he is picked.", "Deni Avdija is going to be good value where he is picked."]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we see something really interesting. We no longer have the &lt;code&gt;puts&lt;/code&gt; command to display our function item by item like in previous examples. Instead, we definitively see the mutations we made to the array reflected in a &lt;em&gt;new array&lt;/em&gt; produced by the &lt;code&gt;map&lt;/code&gt; iterator that contains all the returned values. &lt;/p&gt;

&lt;p&gt;For good measure, here is that same iteration using &lt;code&gt;collect&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;irb(main):008:0&amp;gt; nba_draft_top_10.collect do |prospect|
irb(main):009:1* "#{prospect} is going to be good value where he is picked."
irb(main):010:1&amp;gt; end
=&amp;gt; ["LaMelo Ball is going to be good value where he is picked.", "Onyeka Okongwu is going to be good value where he is picked.", "Anthony Edwards is going to be good value where he is picked.", "Killian Hayes is going to be good value where he is picked.", "James Wiseman is going to be good value where he is picked.", "Obi Toppin is going to be good value where he is picked.", "Tyrese Haliburton is going to be good value where he is picked.", "Aleksej Pokuseveski is going to be good value where he is picked.", "Cole Anthony is going to be good value where he is picked.", "Deni Avdija is going to be good value where he is picked."]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Zero discernable differences.&lt;/p&gt;

&lt;h1&gt;Mutable vs Immutable&lt;/h1&gt;

&lt;p&gt;Since mutation is the key difference with these iterators, it's probably best if we touch on what situations to use each. I'm hardly the best to explain, I did find a really good article &lt;a href="https://blog.logrocket.com/to-mutate-or-immutate/"&gt;here&lt;/a&gt;, though it covers JavaScript uses the principle will remain the same. Now for most of what you will do while you are starting out, functionally, there will be little difference between mutable and immutable iterations. However, when you start building more complex apps, this nuance becomes more important. This is an over-generalization to be sure, but here it is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.&lt;/strong&gt; Use &lt;code&gt;each&lt;/code&gt; when you are iterating through your back-end data. This is the stuff that you wouldn't want to permanently manipulate as it could affect other parts of your app. When using Ruby on Rails, your Controllers are a good example of places you want to use &lt;code&gt;each&lt;/code&gt;.&lt;br&gt;
&lt;strong&gt;2.&lt;/strong&gt; Use &lt;code&gt;map&lt;/code&gt; to iterate and manipulate data you want the user to see (front-end). &lt;code&gt;Map&lt;/code&gt; is often less bulky code-wise to work with since it naturally preserves itself by returning a new array. &lt;/p&gt;

&lt;h1&gt;Ruby Iterations Lab&lt;/h1&gt;

&lt;p&gt;Let's go &lt;code&gt;collect&lt;/code&gt; some practice to help &lt;code&gt;map&lt;/code&gt; out &lt;code&gt;each&lt;/code&gt; of our skills in the &lt;a href="https://github.com/BMWeygant/Ruby-Array_Iteration-Lab"&gt;Ruby Iterations Lab&lt;/a&gt;! &lt;/p&gt;

</description>
      <category>ruby</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Question: Rails 6 App with Devise/Omniauth on Heroku?</title>
      <dc:creator>Brandon Weygant</dc:creator>
      <pubDate>Fri, 26 Jun 2020 15:15:47 +0000</pubDate>
      <link>https://dev.to/bmweygant/question-rails-6-app-with-devise-omniauth-on-heroku-390k</link>
      <guid>https://dev.to/bmweygant/question-rails-6-app-with-devise-omniauth-on-heroku-390k</guid>
      <description>&lt;p&gt;So I've been stuck on this for some time now and was wondering if anyone here has any insight that can help me. For the most part the app works on the site, but there are two known issues I can't seem to resolve on my own:&lt;/p&gt;

&lt;p&gt;1) Password recovery doesn't work, not actually sure if this is all on devise or if I needed an outside mail campaign to do this.&lt;br&gt;
2) Can't login using the Github omniauth link. The primary issue was the page didn't exist and it took me down this rabbit hole where i hardly recognize or understand what my devise controllers and configuration or supposed to be doing anymore. &lt;/p&gt;

&lt;p&gt;Check out the project &lt;a href="https://heroqueststart.herokuapp.com/"&gt;here&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Forgive the ugliness of the site, swear I got some styling planned. I just can't focus on that stuff while I got technical issues like this.&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>rails</category>
      <category>heroku</category>
      <category>devise</category>
    </item>
    <item>
      <title>Ruby Arrays</title>
      <dc:creator>Brandon Weygant</dc:creator>
      <pubDate>Thu, 18 Jun 2020 17:17:49 +0000</pubDate>
      <link>https://dev.to/bmweygant/ruby-arrays-o8n</link>
      <guid>https://dev.to/bmweygant/ruby-arrays-o8n</guid>
      <description>&lt;p&gt;This week we'll be diving deeper into Arrays in Ruby. We touched a bit on them in a previous lesson about Ruby classes, and this time we'll cover them more in depth and demonstrate why they are such a useful programming tool.&lt;/p&gt;

&lt;h1&gt;Array Recap&lt;/h1&gt;

&lt;p&gt;An array is a collection of data stored in list form for your program to access. It is denoted with opening and closing brackets (&lt;code&gt;[]&lt;/code&gt;). A couple of examples of arrays are as follows:&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;numbers_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="mi"&gt;4&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;#This is an array of 5 different Integers.&lt;/span&gt;

&lt;span class="n"&gt;words_array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"words"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"to"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"fill"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"this"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"array"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="c1"&gt;#This is an array of 5 different Strings.&lt;/span&gt;

&lt;span class="n"&gt;single_array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"this, looks, like, a, lot, of, different, words, but, a, syntax, error, makes, this, a, one, string, array"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="c1"&gt;#This is an array with only 1 String.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also declare an empty array in 2 different ways, one like above and the other via the class constructor:&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;my_array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[]&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; []&lt;/span&gt;
&lt;span class="c1"&gt;#Nice and simple&lt;/span&gt;

&lt;span class="n"&gt;my_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="c1"&gt;#=&amp;gt; []&lt;/span&gt;
&lt;span class="c1"&gt;#Same result and a bit more typing.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And that's it, no tricky syntax or creation method. You create an array in the exact same way you would create a varaible in Ruby. As a matter of fact, when declaring an array, think of it as a short cut for declaring multiple variables at one time. An array is a very convenient storage container for a programmer to help keep their program clean and organized. &lt;/p&gt;

&lt;p&gt;Array's are indexed starting with the number 0. This means the first element in each array will be called with the syntax &lt;code&gt;array_name[0]&lt;/code&gt;, the second element &lt;code&gt;array_name[1]&lt;/code&gt;, and so forth. Keep this little detail in mind as you build programs, or your neat little organizational tool will become a serious headache very quickly.&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;numbers_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="mi"&gt;4&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;#An array of 5 elements.&lt;/span&gt;

&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;numbers_array&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;#=&amp;gt; 1&lt;/span&gt;

&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;numbers_array&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;#=&amp;gt; 3&lt;/span&gt;

&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;numbers_array&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;#=&amp;gt; nil&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;One more thing about array indexes. While 0-&amp;gt;1-&amp;gt;2-&amp;gt;etc will move forward from the first element in an array, you can also start from the very end of an array using negative numbers. When doing this the number &lt;code&gt;-1&lt;/code&gt; will always be assigned as the last element in an array, &lt;code&gt;-2&lt;/code&gt; the second to last element, and the first element will have the same negative number as the length of the array.&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;numbers_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="mi"&gt;4&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;#An array of 5 elements.&lt;/span&gt;

&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;numbers_array&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;#=&amp;gt; 1&lt;/span&gt;

&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;numbers_array&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&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;#=&amp;gt; 5&lt;/span&gt;

&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;numbers_array&lt;/span&gt;&lt;span class="p"&gt;[&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;#=&amp;gt; 3&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;numbers_array&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&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;#=&amp;gt; 0 (in our previous example an index of positive 5 returned nil)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Remember negative indexes start at -1 and not zero&lt;/strong&gt;. &lt;/p&gt;

&lt;h1&gt;Array Methods&lt;/h1&gt;

&lt;p&gt;So we can see the value and ease of use of an array vs declaring all those separate variables. But what if you wanted to add or subtract another element to the array? You &lt;em&gt;could&lt;/em&gt; just add or subtract from the array directly for permanent global changes, but what if you only wanted to add or remove an element is more specific cases? What if you want to know how many elements are in an array? Do you want to count each one by hand? No, you do not. Luckily Ruby comes ready to rock with many helpful methods specifically catered to arrays!&lt;/p&gt;

&lt;p&gt;You can view all the possible methods usable on an array with the &lt;code&gt;methods&lt;/code&gt; method as such:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\Brandon&amp;gt;irb
irb(main):001:0&amp;gt; my_array = [1, 2, 3, 4]
=&amp;gt; [1, 2, 3, 4]
irb(main):002:0&amp;gt; my_array.methods
=&amp;gt; [:to_h, :include?, :at, :fetch, :last, :union, :difference, :push, :append, :pop, :shift, :unshift, :each_index, :join, :rotate, :rotate!, :sort!, :sort_by!, :collect!, :map!, :select!, :filter!, :keep_if, :values_at, :delete_at, :delete_if, :reject!, :transpose, :fill, :assoc, :rassoc, :uniq!, :compact, :*, :+, :flatten!, :&amp;amp;, :shuffle, :sample, :compact!, :flatten, :combination, :shuffle!, :-, :repeated_permutation, :sort, :product, :bsearch, :repeated_combination, :count, :find_index, :select, :filter, :reject, :collect, :map, :permutation, :first, :all?, :bsearch_index, :any?, :none?, :one?, :reverse_each, :zip, :take, :take_while, :drop, :drop_while, :cycle, :sum, :uniq, :|, :insert, :&amp;lt;=&amp;gt;, :&amp;lt;&amp;lt;, :index, :rindex, :replace, :==, :clear, :pack, :[], :[]=, :empty?, :eql?, :max, :min, :reverse, :inspect, :concat, :prepend, :reverse!, :length, :size, :each, :to_ary, :delete, :to_a, :to_s, :slice, :slice!, :dig, :hash, :to_set, :find, :entries, :sort_by, :grep, :grep_v, :detect, :find_all, :flat_map, :collect_concat, :inject, :reduce, :partition, :group_by, :minmax, :min_by, :max_by, :minmax_by, :member?, :each_with_index, :each_entry, :each_slice, :each_cons, :each_with_object, :chunk, :slice_before, :slice_after, :slice_when, :chunk_while, :lazy, :chain, :instance_variable_defined?, :remove_instance_variable, :instance_of?, :kind_of?, :is_a?, :tap, :methods, :singleton_methods, :protected_methods, :instance_variables, :instance_variable_get, :instance_variable_set, :private_methods, :public_methods, :method, :singleton_method, :public_send, :public_method, :define_singleton_method, :extend, :to_enum, :enum_for, :===, :=~, :!~, :respond_to?, :freeze, :object_id, :send, :display, :nil?, :class, :singleton_class, :clone, :dup, :itself, :yield_self, :then, :taint, :tainted?, :untaint, :trust, :frozen?, :untrust, :untrusted?, :equal?, :!, :__id__, :instance_exec, :!=, :instance_eval, :__send__]
irb(main):003:0&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's a ton of methods! Granted not all are &lt;code&gt;array&lt;/code&gt; specific, but we'll sort out some of the most popular and need to know ones here. &lt;/p&gt;

&lt;h3&gt;Basic Array Methods&lt;/h3&gt;

&lt;p&gt;These are some of the methods to gather information about your array. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;inspect&lt;/code&gt; - This method returns a &lt;strong&gt;&lt;em&gt;string&lt;/em&gt;&lt;/strong&gt; version of the array containing all the current elements inside of it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\Brandon&amp;gt;irb
irb(main):001:0&amp;gt; my_array = [1, 2, 3, 4]
=&amp;gt; [1, 2, 3, 4]
irb(main):002:0&amp;gt; my_array.inspect
=&amp;gt; "[1, 2, 3, 4]"
irb(main):003:0&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;length&lt;/code&gt; - This method returns the number of elements currently in an array. This method will be frequently used in a &lt;strong&gt;&lt;em&gt;ton&lt;/em&gt;&lt;/strong&gt; of programming math and troubleshooting, so it's best to familiarize yourself with it quickly.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\Brandon&amp;gt;irb
irb(main):001:0&amp;gt; my_array = [1, 2, 3, 4]
=&amp;gt; [1, 2, 3, 4]
irb(main):002:0&amp;gt; my_array.inspect
=&amp;gt; "[1, 2, 3, 4]"
irb(main):003:0&amp;gt; my_array.length
=&amp;gt; 4
irb(main):004:0&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;index&lt;/code&gt; - This method will return the &lt;em&gt;index number&lt;/em&gt; of the first occurrence of its given argument.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\Brandon&amp;gt;irb
irb(main):001:0&amp;gt; my_array = [1, 1, 2, 3, 4]
=&amp;gt; [1, 1, 2, 3, 4]
irb(main):002:0&amp;gt; my_array.index(1)
=&amp;gt; 0
irb(main):003:0&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note we only get '0' as the index even though we have multiple '1's in the array. You probably won't be performing this very often, but can be useful in a pinch in larger arrays to quickly identify an index number when needed.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;first&lt;/code&gt; &amp;amp; &lt;code&gt;last&lt;/code&gt; - These methods will return the value of the first or last element in an array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\Brandon&amp;gt;irb
irb(main):001:0&amp;gt; my_array = [1, 2, 3, 4]
=&amp;gt; [1, 2, 3, 4]
irb(main):002:0&amp;gt; my_array.first
=&amp;gt; 1
irb(main):003:0&amp;gt; my_array.last
=&amp;gt; 4
irb(main):004:0&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;sort&lt;/code&gt; - A method that will sort your array. By default, it will sort in ascending order (lowest to highest).&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;my_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;3&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;4&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="nb"&gt;print&lt;/span&gt; &lt;span class="n"&gt;my_array&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;#=&amp;gt; [1, 2, 3, 4]&lt;/span&gt;
&lt;span class="c1"&gt;#We used print to see the return in array form.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;reverse&lt;/code&gt; - As the name implies, this will reverse your array.&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;my_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="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

&lt;span class="nb"&gt;print&lt;/span&gt; &lt;span class="n"&gt;my_array&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;reverse&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; [4, 3, 2, 1]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;Adding and Removing Elements&lt;/h3&gt;

&lt;p&gt;Arrays come with several methods to quickly manipulate the number of elements in them. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; &lt;strong&gt;(AKA The Shovel Operator)&lt;/strong&gt; - The shovel operator will add an element to the &lt;em&gt;end&lt;/em&gt; of an existing array very painlessly. It is the preferred method to add items to an array due to it's simplicity, though there are other methods you must use if you need something injected elsewhere into an array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\Brandon&amp;gt;irb
irb(main):001:0&amp;gt; my_array = [1, 2, 3, 4]
=&amp;gt; [1, 2, 3, 4]
irb(main):002:0&amp;gt; my_array &amp;lt;&amp;lt; 5
=&amp;gt; [1, 2, 3, 4, 5]
irb(main):003:0&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;push&lt;/code&gt; - This method is the longer equivalent of the &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; operator. It add's a new item to the &lt;em&gt;end&lt;/em&gt; of the array.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\Brandon&amp;gt;irb
irb(main):001:0&amp;gt; my_array = [1, 2, 3, 4]
=&amp;gt; [1, 2, 3, 4]
irb(main):002:0&amp;gt; my_array.push(5)
=&amp;gt; [1, 2, 3, 4, 5]
irb(main):003:0&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;unshift&lt;/code&gt; - This method will add an element to the &lt;em&gt;front&lt;/em&gt; of an array. Not as common as &lt;code&gt;&amp;lt;&amp;lt;&lt;/code&gt; or &lt;code&gt;push&lt;/code&gt; but more often than not you will be manipulating either the first or last element in an array so it's good to keep this one in mind.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\Brandon&amp;gt;irb
irb(main):001:0&amp;gt; my_array = [1, 2, 3, 4]
=&amp;gt; [1, 2, 3, 4]
irb(main):002:0&amp;gt; my_array.unshift(0)
=&amp;gt; [0, 1, 2, 3, 4]
irb(main):003:0&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;pop&lt;/code&gt; - This method will remove the &lt;em&gt;last&lt;/em&gt; element from an array and return it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\Brandon&amp;gt;irb
irb(main):001:0&amp;gt; my_array = [1, 2, 3, 4]
=&amp;gt; [1, 2, 3, 4]
irb(main):002:0&amp;gt; my_array.pop
=&amp;gt; 3
irb(main):003:0&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;shift&lt;/code&gt; - This method will remove the &lt;em&gt;first&lt;/em&gt; element in an array and returns it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\Brandon&amp;gt;irb
irb(main):001:0&amp;gt; my_array = [1, 2, 3, 4]
=&amp;gt; [1, 2, 3, 4]
irb(main):002:0&amp;gt; my_array.shift
=&amp;gt; 1
irb(main):003:0&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; With &lt;code&gt;unshift&lt;/code&gt; &amp;amp; &lt;code&gt;push&lt;/code&gt; you have to pass the value of the element you wish to add as an argument, but since &lt;code&gt;pop&lt;/code&gt; &amp;amp; &lt;code&gt;shift&lt;/code&gt; are removing already known elements no argument is necessary. &lt;/p&gt;

&lt;p&gt;&lt;code&gt;delete_at&lt;/code&gt;- This method will remove an element at a specific index. Rarely used, but it's good to know if you ever find yourself needing to add an element into the middle of an array for whatever reason.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\Brandon&amp;gt;irb
irb(main):001:0&amp;gt; my_array = [1, 2, 3, 4]
=&amp;gt; [1, 2, 3, 4]
irb(main):002:0&amp;gt; my_array.delete_at(2)
=&amp;gt; 3
irb(main):003:0&amp;gt;my_array
=&amp;gt; [1, 2, 4]
irb(main):004:0&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;insert&lt;/code&gt; - This method adds an element to an array at a specific index. It takes 2+ arguments, the first is the index you want to start the insert at, and the second (and possibly more arguments) are the elements you want to add.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\Users\Brandon&amp;gt;irb
irb(main):001:0&amp;gt; my_array = ["All", "Lives", "matter", "yours", "too!"]
=&amp;gt; ["All", "Lives", "matter", "yours", "too!"] 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this array we a very true an encouraging sentiment, but it doesn't quite capture our feelings. We can start by removing the "yours" element with &lt;code&gt;delete_at&lt;/code&gt;.&lt;br&gt;
&lt;strong&gt;Note, arrays are not great sentence constructors!&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;irb(main):002:0&amp;gt; my_array.delete_at(3)
=&amp;gt; "yours"
#=&amp;gt; ["All", "Lives", "matter", "too!"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now let's add a few more words with &lt;code&gt;insert&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;irb(main):003:0&amp;gt; my_array.insert(2, "can't")
=&amp;gt; ["All", "Lives", "can't", "matter", "too!"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We've definitely changed the sentiment here, and not for the better. Let's fix it with another &lt;code&gt;insert&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;irb(main):004:0&amp;gt; my_array.insert(4, "until", "Black", "Lives", "Matter")
=&amp;gt; ["All", "Lives", "can't", "matter", "until", "Black", "Lives", "Matter", "too!"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Perfect!&lt;/p&gt;

&lt;h1&gt;Conclusion&lt;/h1&gt;

&lt;p&gt;This is a very long blog post, and with good reason! Arrays are a major part of programming, and there is a ton of ground to cover. Quite simply there is absolutely no way out of a ton of reading and research on this subject. A good example will be next week when we cover part two, array iteration where we introduce even &lt;em&gt;more&lt;/em&gt; array methods! &lt;/p&gt;

&lt;h1&gt;Ruby Arrays Lab&lt;/h1&gt;

&lt;p&gt;You guessed it, another lab! Let's drive these lesson home with a little practice. Complete the &lt;a href="https://github.com/BMWeygant/Ruby-Array-Methods-Lab"&gt;Ruby Array Methods Lab&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Ruby IRB</title>
      <dc:creator>Brandon Weygant</dc:creator>
      <pubDate>Tue, 02 Jun 2020 18:18:26 +0000</pubDate>
      <link>https://dev.to/bmweygant/ruby-irb-15fe</link>
      <guid>https://dev.to/bmweygant/ruby-irb-15fe</guid>
      <description>&lt;p&gt;I'm not in such a good enough mood to go and write this with as much attention as it deserves with everything going on in this country right now. A lot of hurt is happening, and a lot of change is necessary. &lt;/p&gt;

&lt;p&gt;Anyways, here's a short intro on Ruby's irb command line. This is a useful tool for practicing Ruby and trying new concepts as well ass different tricks. &lt;/p&gt;

&lt;h1&gt;What is IRB?&lt;/h1&gt;

&lt;p&gt;IRB - short for "Interactive Ruby" - is a tool to interactively execute Ruby expressions read from the standard input. It's as easy to start an IRB session as typing &lt;code&gt;irb&lt;/code&gt; in your shell after installing Ruby.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\users\Brandon&amp;gt;irb
irb(main):001:0&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Something like &lt;code&gt;irb(main):001:0&amp;gt;&lt;/code&gt; above should appear with the '_' flashing. This means you have successfully entered an irb session.&lt;/p&gt;

&lt;h1&gt;What Can You Do Inside A Session?&lt;/h1&gt;

&lt;p&gt;IRB is designed to be a temporary session that you can terminate whenever your ready to start actual work. It's main purpose is to provide a safe place to practice without actually interfering with you program. For example, you can declare a variable like you would in any ruby program:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;C:\users\Brandon&amp;gt;irb
irb(main):001:0&amp;gt; x = "Black Lives Matter"
=&amp;gt; "Black Lives Matter"
irb(main):002:0&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can call the variable any time during your session before you close it simply by typing the variable and pressing &lt;code&gt;enter&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;irb(main):002:0&amp;gt; x
=&amp;gt; "Black Lives Matter"
irb(main):003:0&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also build functions in irb. This is a bit clunky, as it is designed to be done line by line like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;b(main):001:0&amp;gt; def injustice
irb(main):002:1&amp;gt; puts "George Floyd, Natosha McDade, Yassin Mohamed, Finan H. Berhe, Sean Reed, Steven Demarco Taylor, Breonna Taylor, Ariane McCree, Terrance Franklin, Miles Hall, Darius Tarver, William Green, Samuel David Mallard, Kwame Jones, Devon Bailey, Christopher Whitfield, Anthony Hill, DeVon Bailey, Eric Logan, Jamarion Robinson, Gregory Hill Jr, JaQuavion Slaton, Ryan Twyman, Brandon Webber, Jimmy Atchison, Willie McCoy, Emantic Fitzgerald Bradford J, Dettrick Griffin, Jemel Roberson, DeAndre Ballard, Botham Shem Jean, Robert Lawrence White, Anthony Lamar Smith, Ramarley Graham, Manuel Loggins Jr, Trayvon Martin, Wendell Allen, Kendrec McDade, Larry Jackson Jr, Jonathan Ferrell, Jordan Baker, Victor White III, Dontre Hamilton, Eric Garner, John Crawford III, Michael Brown, Ezell Ford, Dante Parker, Kajieme Powell, Laquan McDonald, Akai Gurley, Tamir Rice, Rumain Brisbon, Jerame Reid, Charly Keunang, Tony Robinson, Walter Scott, Freddie Gray, Brendon Glenn, Samuel DuBose, Christian Taylor, Jamar Clark, Mario Woods, Quintonio LeGrier, Gregory Gunn, Akiel Denkins, Alton Sterling, Philando Castile, Terrence Sterling, Terence Crutcher, Keith Lamont Scott, Alfred Olango, Jordan Edwards, Stephon Clark, Danny Ray Thomas, DeJuan Guillory, Patrick Harmon, Jonathan Hart, Maurice Granton, Julius Johnson, Jamee Johnson, Michael Dean, and many, many, many others."
irb(main):003:1&amp;gt; end
=&amp;gt; :injustice
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And just like with variables we can call that function anytime during our session by typing it in the shell:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;irb(main):004:0&amp;gt; injustice
George Floyd, Natosha McDade, Yassin Mohamed, Finan H. Berhe, Sean Reed, Steven Demarco Taylor, Breonna Taylor, Ariane McCree, Terrance Franklin, Miles Hall, Darius Tarver, William Green, Samuel David Mallard, Kwame Jones, Devon Bailey, Christopher Whitfield, Anthony Hill, DeVon Bailey, Eric Logan, Jamarion Robinson, Gregory Hill Jr, JaQuavion Slaton, Ryan Twyman, Brandon Webber, Jimmy Atchison, Willie McCoy, Emantic Fitzgerald Bradford J, Dettrick Griffin, Jemel Roberson, DeAndre Ballard, Botham Shem Jean, Robert Lawrence White, Anthony Lamar Smith, Ramarley Graham, Manuel Loggins Jr, Trayvon Martin, Wendell Allen, Kendrec McDade, Larry Jackson Jr, Jonathan Ferrell, Jordan Baker, Victor White III, Dontre Hamilton, Eric Garner, John Crawford III, Michael Brown, Ezell Ford, Dante Parker, Kajieme Powell, Laquan McDonald, Akai Gurley, Tamir Rice, Rumain Brisbon, Jerame Reid, Charly Keunang, Tony Robinson, Walter Scott, Freddie Gray, Brendon Glenn, Samuel DuBose, Christian Taylor, Jamar Clark, Mario Woods, Quintonio LeGrier, Gregory Gunn, Akiel Denkins, Alton Sterling, Philando Castile, Terrence Sterling, Terence Crutcher, Keith Lamont Scott, Alfred Olango, Jordan Edwards, Stephon Clark, Danny Ray Thomas, DeJuan Guillory, Patrick Harmon, Jonathan Hart, Maurice Granton, Julius Johnson, Jamee Johnson, Michael Dean, and many, many, many others.
=&amp;gt; nil
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Don't mind the &lt;code&gt;nil&lt;/code&gt; return, its just how it works behind the scenes. The important thing is that we did get the return we were expecting. Functions are clunky as you can see in irb, and it's not the ideal environment (especially if you have complex functions), but it is a good place to work out any kinks or fears you have about functions.&lt;/p&gt;

&lt;p&gt;You can end the irb session by typing &lt;code&gt;exit&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;irb(main):011:0&amp;gt; exit

C:\users\Brandon&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is a ton more, like creating new instances of a class - including custom classes. Really, outside of the sometimes clunky interface, irb doesn't have many limitations to what you can't do with Ruby. The important thing to remember is it is a practice tool, and when you terminate the sessions you lose the data you inputted. &lt;/p&gt;

&lt;p&gt;Stay safe out there.&lt;/p&gt;

</description>
      <category>blacklivesmatter</category>
      <category>ruby</category>
      <category>tutorial</category>
      <category>blackouttuesday</category>
    </item>
    <item>
      <title>Ruby Data Type Classes: Numbers, Arrays, Symbols, &amp; Hashes</title>
      <dc:creator>Brandon Weygant</dc:creator>
      <pubDate>Mon, 25 May 2020 19:29:07 +0000</pubDate>
      <link>https://dev.to/bmweygant/ruby-data-type-classes-numbers-arrays-symbols-hashes-2kka</link>
      <guid>https://dev.to/bmweygant/ruby-data-type-classes-numbers-arrays-symbols-hashes-2kka</guid>
      <description>&lt;p&gt;Before we dive deeper into some more of the basics of Ruby, I felt it necessary to explain more about classes. We'll discuss the different classes above, and give some light examples this week, before diving more in-depth in our following lessons. If you think classes sound a little advanced for you, fear not! We've already covered a few classes in previous lessons: the &lt;code&gt;String&lt;/code&gt; class &amp;amp; the Boolean classes &lt;code&gt;TrueClass&lt;/code&gt; &amp;amp; &lt;code&gt;FalseClass&lt;/code&gt;. EZPZ!&lt;/p&gt;

&lt;h1&gt;What is a Class?&lt;/h1&gt;

&lt;p&gt;In Ruby, a class is basically the blueprint for building an object. While Ruby provides you the freedom to define your own classes (covered in a later lesson), the classes we will be discussing are the basic classes that already come built into Ruby. The main ones we will cover (in addition to the ones we already have) are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;TrueClass &amp;amp; FalseClass - Creates an instance of a `true` or `false` object.&lt;/li&gt;
&lt;li&gt;String Class - A string is a sequence of characters, denoted in programming with quotation marks.&lt;/li&gt;
&lt;li&gt;Number Classes - "Number" is not a class itself, but is a reference to several number-based classes.&lt;/li&gt;
&lt;li&gt;Array Class - An array is an ordered, integer-indexed collection of any objects. &lt;/li&gt;
&lt;li&gt;Symbol class - Symbols are generally used to identify a specific resource such as a method, variable, hash key, etc.&lt;/li&gt;
&lt;li&gt;Hash Class - A collection of `keys` and their `values`.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The benefits of being a part of a &lt;code&gt;class&lt;/code&gt; in Ruby, is that each class provides the blueprint as well as various built-in methods that every instance of that class will have access to. When dealing with a certain data type, you can use the &lt;code&gt;methods&lt;/code&gt; method to view what methods are available to you for that data type. For instance:&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;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Hello, world!"&lt;/span&gt;
&lt;span class="c1"&gt;#x would be an instance of String class&lt;/span&gt;

&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;methods&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; to_h&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt;include?&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt;at&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt;fetch&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt;last&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt;union&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt;difference&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt;push&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt;...&lt;/span&gt;

&lt;span class="c1"&gt;#Lists all String class methods&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whereas&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;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="c1"&gt;#x would be an instance of Integer class&lt;/span&gt;

&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;methods&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; -@&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; **&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; &amp;lt;=&amp;gt;&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; upto&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; &amp;lt;&amp;lt;&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; &amp;lt;=&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; &amp;gt;=&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; ==&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt;...&lt;/span&gt;

&lt;span class="c1"&gt;#Lists all Integer class methods&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see from the list we have different methods available to &lt;code&gt;x&lt;/code&gt; depending on what class its &lt;code&gt;value&lt;/code&gt; is classified as. Knowing what methods are available to you is paramount as a developer.&lt;/p&gt;

&lt;h1&gt;Numbers Classes&lt;/h1&gt;

&lt;p&gt;Ruby uses quite a few different classes for numbers, each one meant to capture certain unique features different types of numbers could have. Numbers can become a very hefty topic very quickly, so I'll keep it quick and only mention &lt;code&gt;Integer&lt;/code&gt; and &lt;code&gt;Float&lt;/code&gt; classes, as those are by far the most frequent you will be using.&lt;/p&gt;

&lt;h3&gt;Integer Class&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;Integer&lt;/code&gt; class is simple and straightforward: it holds whole numbers. Anything with a decimal, fraction, or some other demarkation of partial value does not fit into the &lt;code&gt;Integer&lt;/code&gt; class.&lt;/p&gt;

&lt;h3&gt;Float Class&lt;/h3&gt;

&lt;p&gt;Used to identify decimal numbers. &lt;code&gt;Pi&lt;/code&gt; would be an example of a &lt;code&gt;Float&lt;/code&gt; class instance.&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="no"&gt;Math&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;PI&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;class&lt;/span&gt; 
&lt;span class="c1"&gt;#=&amp;gt; Float&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;On a side note, when using math in Ruby such as &lt;code&gt;1/2&lt;/code&gt; (the &lt;code&gt;/&lt;/code&gt; stands for 'divided by' in Ruby), by default Ruby will try to force the solution to be an an &lt;code&gt;Integer&lt;/code&gt; since both the dividend and divisor fall under the &lt;code&gt;Integer&lt;/code&gt; class. By contrast, &lt;code&gt;1.5/3&lt;/code&gt; would naturally fall under the &lt;code&gt;Float&lt;/code&gt; class since 1.5 is a &lt;code&gt;Float&lt;/code&gt;. When using math in Ruby with whole numbers that &lt;em&gt;could&lt;/em&gt; lead to a decimal value, it's good practice to convert to float with the &lt;code&gt;.to_f&lt;/code&gt; method to prevent Ruby from rounding to the nearest &lt;code&gt;Integer&lt;/code&gt;.&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;x&lt;/span&gt; &lt;span class="o"&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="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; 
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;class&lt;/span&gt;

&lt;span class="c1"&gt;#=&amp;gt; 0&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; Integer&lt;/span&gt;

&lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="o"&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_f&lt;/span&gt;

&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; 
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;class&lt;/span&gt;

&lt;span class="c1"&gt;#=&amp;gt; 0.5&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; Float&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;Array Class&lt;/h1&gt;

&lt;p&gt;As stated earlier, an array is an ordered, integer-indexed collection of any objects. You would denote an &lt;code&gt;array&lt;/code&gt; in Ruby with brackets &lt;code&gt;[]&lt;/code&gt;. You separate each object in an array with a &lt;code&gt;,&lt;/code&gt;. A few examples of an array are:&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;numbers_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="mi"&gt;4&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;#This is an array of 5 different Integers.&lt;/span&gt;

&lt;span class="n"&gt;words_array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"words"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"to"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"fill"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"this"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"array"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="c1"&gt;#This is an array of 5 different Strings.&lt;/span&gt;

&lt;span class="n"&gt;single_array&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"this, looks, like, a, lot, of, different, words, but, a, syntax, error, makes, this, a, one, string, array"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="c1"&gt;#This is an array with only 1 String.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can immediately see the value in arrays as storage containers. An array can give us access to multiple objects in a single location! &lt;/p&gt;

&lt;p&gt;Arrays are indexed in order starting with 0. This means that the first object in an array will have an index number of 0, the second an index of 1, and so on. You can access a specific index in an array with the syntax &lt;code&gt;array_name[index#]&lt;/code&gt;. Using the arrays above, try to guess the return value of &lt;code&gt;numbers_array[2]&lt;/code&gt;, &lt;code&gt;single_array[1]&lt;/code&gt;, &lt;code&gt;words_array[0]&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;If you guessed &lt;code&gt;numbers_array[2]&lt;/code&gt; = 3&lt;code&gt;,&lt;/code&gt;single_array[1]&lt;code&gt;=&lt;/code&gt;nil&lt;code&gt;(means 'nothing'), &amp;amp;&lt;/code&gt;words_array[0] = &lt;code&gt;words&lt;/code&gt; you were right. Anything else means you were less right :). &lt;/p&gt;

&lt;p&gt;Comparing the above to our earlier lesson on variables, In addition to storing data in list form, think of the index number as also setting a variable to all the different pieces of data inside an array. &lt;/p&gt;

&lt;h1&gt;Symbol Class&lt;/h1&gt;

&lt;p&gt;Symbols generally point to a specific resource in your program. You denote them in ruby with a &lt;code&gt;:&lt;/code&gt; in front of the word you want as a symbol like &lt;code&gt;:brandon&lt;/code&gt;. The key benefit of using symbols is that they are immutable and will always point to the same object. By comparison, a string even if totally identical, will always be a different object and take up more memory to account for mutability. The most basic way to understand this is to return multiple of the same data type with equal value:&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;"Brandon"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object_id&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Brandon"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object_id&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Brandon"&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object_id&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; 42553140&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; 42552980&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; 42552920&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note how all the &lt;code&gt;object_id&lt;/code&gt;'s are different. &lt;/p&gt;

&lt;p&gt;Now the same thing but using the &lt;code&gt;Symbol&lt;/code&gt; &lt;code&gt;:brandon&lt;/code&gt;&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="ss"&gt;:brandon&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object_id&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="ss"&gt;:brandon&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object_id&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="ss"&gt;:brandon&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;object_id&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; 1102428&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; 1102428&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; 1102428&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now all the id's are the same. This immutability is primarily why symbols make superior hash keys because they will point to the same value without using as much memory, hence making your program less bulky overall. More on &lt;code&gt;Hash&lt;/code&gt; class right below, but note the two ways to make a symbol into a hash key:&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;instructor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:name&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"Brandon Weygant"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This first way is the native way to do it in Ruby. However, as of Ruby 1.9 and above, they simplified the syntax to make it look like a more classical &lt;code&gt;key:value&lt;/code&gt; pairing like 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="n"&gt;instructor&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;name: &lt;/span&gt;&lt;span class="s2"&gt;"Brandon Weygant"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;name:&lt;/code&gt; will still read as a &lt;code&gt;Symbol&lt;/code&gt; in this case, and this syntax is the preferable way to do it today. Note that if you use keys that aren't symbols inside a hash, you will have to continue to use the &lt;code&gt;=&amp;gt;&lt;/code&gt; rocket syntax.&lt;/p&gt;

&lt;h1&gt;Hash Class&lt;/h1&gt;

&lt;p&gt;As stated earlier, a &lt;code&gt;Hash&lt;/code&gt; is a collection of &lt;code&gt;keys&lt;/code&gt; and their &lt;code&gt;values&lt;/code&gt;. A &lt;code&gt;hash&lt;/code&gt; is denoted with the curly brackets &lt;code&gt;{}&lt;/code&gt;. Inside the &lt;code&gt;{}&lt;/code&gt; you would have a key pointing to a value (like above in &lt;code&gt;Symbols&lt;/code&gt;) and multiple entries would be separated with comma's, just like in arrays&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;Hash&lt;/code&gt; has many similarities to an &lt;code&gt;Array&lt;/code&gt;, but some key differences as well. Where an &lt;code&gt;array&lt;/code&gt; is a list, &lt;code&gt;hashes&lt;/code&gt; are dictionaries where we look up the value of a key by using the key directly. This means you aren't bound by knowing what index# an array list item has to call it, you simply have to remember the key you used. Example:&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;todays_lessons&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;number: &lt;/span&gt;&lt;span class="s2"&gt;"We learned about number classes."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="ss"&gt;array: &lt;/span&gt;&lt;span class="s2"&gt;"We learned about number classes."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="ss"&gt;symbol: &lt;/span&gt;&lt;span class="s2"&gt;"We learned about the Symbol class."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="ss"&gt;hash: &lt;/span&gt;&lt;span class="s2"&gt;"We are currently learning about the hash class!"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If we tried to &lt;code&gt;puts todays_lessons[1]&lt;/code&gt;, instead of getting the &lt;code&gt;:array&lt;/code&gt; value, we'd get &lt;code&gt;nil&lt;/code&gt; instead. The correct syntax to return the &lt;code&gt;:array&lt;/code&gt; value is:&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="n"&gt;todays_lessons&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:array&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Amazingly simple, right? If an Array is designed to be a list of your classes, a hash could be used as an equivalent to the notes you took while in class. &lt;/p&gt;

&lt;h1&gt;Conclusion&lt;/h1&gt;

&lt;p&gt;This is a lot to unpack in a day, but the basics taught here will be vital to understanding as we dive deeper into Math, Array manipulation, iteration, and Hashes. There is a &lt;em&gt;ton&lt;/em&gt; of information we haven't covered on each of these. I just hope this gives you a general idea of how Ruby uses different classes to organize and enhance the unique properties each data type brings to the table.   &lt;/p&gt;

&lt;p&gt;For now take a break and happy Memorial Day!.&lt;/p&gt;

&lt;h1&gt;Ruby Data Types Lab&lt;/h1&gt;

&lt;p&gt;We've unpacked a lot in this lesson, covering several data types you may or may not already be familiar with. Let's embed that by completing the tasks found in the &lt;a href="https://github.com/BMWeygant/Ruby-Data-Types-Lab"&gt;Ruby Data Types Lab&lt;/a&gt;!&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Ruby Loops</title>
      <dc:creator>Brandon Weygant</dc:creator>
      <pubDate>Wed, 20 May 2020 21:49:40 +0000</pubDate>
      <link>https://dev.to/bmweygant/ruby-loops-n27</link>
      <guid>https://dev.to/bmweygant/ruby-loops-n27</guid>
      <description>&lt;p&gt;Today we're going to go over the concept of looping in Ruby. &lt;strong&gt;Looping&lt;/strong&gt; is an action that tells our program to do the same thing over and over again with a few lines, rather than manually typing out our desired loop length. &lt;/p&gt;

&lt;h1&gt;Why Loop?&lt;/h1&gt;

&lt;p&gt;Simple answer: because as programmers we aspire to be as lazy as possible.&lt;/p&gt;

&lt;p&gt;Think a minute about writing a program that requires you to perform an action 5 times, then imagine having to do it 100 times. What problems could you potentially run into typing all occurrences manually? First is a matter of convenience, even if you copy/paste to ensure all the lines are &lt;strong&gt;&lt;em&gt;exactly&lt;/em&gt;&lt;/strong&gt; the same, that's still a tedious manual task that takes away time from improving your program elsewhere. Next, what if you lose count after say 47? What if you accidentally type it in only 97 times? 103 times? This could potentially cause your program to not work as intended in other parts of your code as well.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Loops&lt;/strong&gt; automate this process for us with only a couple lines of code in Ruby. A program that would require a &lt;code&gt;String&lt;/code&gt; to be repeated 100x would use 100+ lines of code if manually looped. You can perform the same functionality in Ruby with about 3 lines of code:&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;100&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;times&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Here we go 'round!"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And just like that, a seemingly daunting task is complete in a matter of seconds!&lt;/p&gt;

&lt;p&gt;Ruby has several different types of loops, some with overlapping functionality and some meant to be more niche in use. We'll go over some of the more common types of loops and explain them in greater detail below.&lt;/p&gt;

&lt;h1&gt;Times Loops&lt;/h1&gt;

&lt;p&gt;Let's start by breaking down the above loop, and highlight the keys that make this function:&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;100&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;times&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Here we go 'round!"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;code&gt;100.times&lt;/code&gt; is the number of times we want our program to perform the following action. The number in front of &lt;code&gt;times&lt;/code&gt; also serves as a built-in &lt;code&gt;break&lt;/code&gt; of the loop, where some other loop types require you to add it in elsewhere. &lt;/li&gt;
&lt;li&gt;the &lt;code&gt;do&lt;/code&gt;/&lt;code&gt;end&lt;/code&gt; creates a block that tells our program what action we want to perform. In this case &lt;code&gt;puts&lt;/code&gt; "Here we go 'round!" The &lt;code&gt;do&lt;/code&gt;/&lt;code&gt;end&lt;/code&gt; block will be a common participant in a number of Ruby lessons. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The beauty of Ruby is it's designed with being programmer-friendly as it's #1 priority. &lt;code&gt;times&lt;/code&gt; is one of the best examples of that in the entire language.  &lt;/p&gt;

&lt;h1&gt;The "Loop" Keyword&lt;/h1&gt;

&lt;p&gt;Next up is the &lt;code&gt;loop&lt;/code&gt; keyword. &lt;code&gt;loop&lt;/code&gt; is the simplest construct we have for looping in Ruby. It will just execute a block (the action(s) between &lt;code&gt;do&lt;/code&gt;/&lt;code&gt;end&lt;/code&gt;) over and over until it is told to stop.&lt;/p&gt;

&lt;p&gt;Let's built a similar method as above from scratch:&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="kp"&gt;loop&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Here we go 'round!"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will put the string "Here we go 'round!" into our console in an eternal loop until we stop it with &lt;code&gt;ctrl&lt;/code&gt;+&lt;code&gt;c&lt;/code&gt;. Not terribly useful overall in its current form if you ask me. Let's add a &lt;code&gt;break&lt;/code&gt; command to stop the loop on its own:&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="kp"&gt;loop&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Here we go 'round!"&lt;/span&gt;
&lt;span class="k"&gt;break&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="c1"&gt;# returns =&amp;gt;&lt;/span&gt;
&lt;span class="c1"&gt;#Here we go 'round!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So now we have a "loop" that only executes our desired command once. The thing is &lt;code&gt;loop&lt;/code&gt; is so simple, that it requires a bit more effort to work at the same level as &lt;code&gt;times&lt;/code&gt;, which kind of defeats the point as Rubyists. &lt;/p&gt;

&lt;p&gt;If we wanted to write a &lt;code&gt;loop&lt;/code&gt; command equivalent to our &lt;code&gt;times&lt;/code&gt; command above, we would have to add a counter to keep track of when to break the loop like such:&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;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="kp"&gt;loop&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Here we go 'round!"&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That is almost triple the number of lines it took our &lt;code&gt;times&lt;/code&gt; loop to accomplish the same task. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; You may be wondering what the &lt;code&gt;+=&lt;/code&gt; is doing. It basically performs the same function as the line &lt;code&gt;counter = counter + 1&lt;/code&gt; which increments and keeps track of the updated value of the &lt;code&gt;counter&lt;/code&gt; variable. It simply condenses the code. &lt;/p&gt;

&lt;p&gt;Since we have a &lt;code&gt;counter&lt;/code&gt; variable, I'll take this opportunity to demonstrate how to keep track of variables inside loops. Stop me if this looks familiar to 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="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="kp"&gt;loop&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
    &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Here we go 'round &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;counter&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; times!"&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="c1"&gt;#returns =&amp;gt;&lt;/span&gt;
&lt;span class="c1"&gt;#Here we go 'round 1 times!&lt;/span&gt;
&lt;span class="c1"&gt;#Here we go 'round 2 times!&lt;/span&gt;
&lt;span class="c1"&gt;#...&lt;/span&gt;
&lt;span class="c1"&gt;#Here we go 'round 99 times!&lt;/span&gt;
&lt;span class="c1"&gt;#Here we go 'round 100 times!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Yup, we can interpolate with &lt;code&gt;#{variable}&lt;/code&gt; inside loops to display and even manipulate the current values of variables.&lt;/p&gt;

&lt;h1&gt;While Loops&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;while&lt;/code&gt; loops provide a unique approach to a similar end. Basically &lt;code&gt;while&lt;/code&gt; translates the given condition to a &lt;code&gt;boolean&lt;/code&gt;, and if that condition is &lt;code&gt;true&lt;/code&gt; the &lt;code&gt;while&lt;/code&gt; loop will then execute until the condition is &lt;code&gt;false&lt;/code&gt;. Like &lt;code&gt;times&lt;/code&gt; &lt;code&gt;while&lt;/code&gt; is it's own built-in &lt;code&gt;break&lt;/code&gt;, so there is no need to declare a direct &lt;code&gt;break&lt;/code&gt; inside the action like with &lt;code&gt;loop&lt;/code&gt;. Writing a loop like above in this style would look like 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="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Here we go 'round!"&lt;/span&gt;
&lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Removing the &lt;code&gt;break&lt;/code&gt; command saves us some space, but in a strict counting situation &lt;code&gt;while&lt;/code&gt; still isn't as advantageous as the &lt;code&gt;times&lt;/code&gt; loop. However, in slightly more complex programs, &lt;code&gt;while&lt;/code&gt; has some strong advantages over &lt;code&gt;times&lt;/code&gt;. For example, if we had an adventurer who was poisoned and losing health, we would want to keep track of our HP so we know when to use our auto-revive potions, right? And we would definitely need a reminder to pop up when we died from the poison too, right?&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;hp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
&lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"poisoned"&lt;/span&gt;
&lt;span class="n"&gt;potions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;

&lt;span class="k"&gt;while&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s2"&gt;"poisoned"&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;hp&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="n"&gt;hp&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"HP: &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;hp&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;hp&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;potions&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"You've used an auto-revive potion!"&lt;/span&gt;
        &lt;span class="n"&gt;potions&lt;/span&gt; &lt;span class="o"&gt;-=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
        &lt;span class="n"&gt;hp&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;100&lt;/span&gt;
        &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"normal"&lt;/span&gt;
        &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"HP: &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;hp&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
    &lt;span class="k"&gt;elsif&lt;/span&gt; &lt;span class="n"&gt;hp&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;potions&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
        &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"The poison was too much to bear!"&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code is a bit busy, but doesn't contain anything we haven't covered already! The gist is we set initial values for &lt;code&gt;hp&lt;/code&gt;, &lt;code&gt;status&lt;/code&gt;. &amp;amp; &lt;code&gt;potions&lt;/code&gt; and manipulated them throughout the &lt;code&gt;while&lt;/code&gt; loop. Using &lt;code&gt;times&lt;/code&gt; in this situation would require multiple loops and more lines for what would likely be a less desirable result. Also note the &lt;code&gt;do&lt;/code&gt; in &lt;code&gt;while&lt;/code&gt; is not necessary&lt;/p&gt;

&lt;p&gt;On a more personal note, I'm glad we had enough potions to survive being poisoned!&lt;/p&gt;

&lt;h1&gt;Until Loops&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;unitl&lt;/code&gt; is basically the &lt;em&gt;inverse&lt;/em&gt; of &lt;code&gt;while&lt;/code&gt;. Where a &lt;code&gt;while&lt;/code&gt; loop executes when something is &lt;code&gt;true&lt;/code&gt;, an &lt;code&gt;unitl&lt;/code&gt; loop will execute &lt;em&gt;until&lt;/em&gt; something becomes true. For example:&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;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="k"&gt;until&lt;/span&gt; &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="mi"&gt;20&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Almost 20!"&lt;/span&gt;
  &lt;span class="n"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just like &lt;code&gt;while&lt;/code&gt; the &lt;code&gt;do&lt;/code&gt; is optional.&lt;/p&gt;

&lt;p&gt;While you can do complex code with &lt;code&gt;until&lt;/code&gt;, in my opinion, the best time to use &lt;code&gt;until&lt;/code&gt; is as a statement modifier. Example:&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;i&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;i&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="k"&gt;until&lt;/span&gt; &lt;span class="n"&gt;i&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;#returns =&amp;gt;&lt;/span&gt;
&lt;span class="c1"&gt;#1&lt;/span&gt;
&lt;span class="c1"&gt;#2&lt;/span&gt;
&lt;span class="c1"&gt;#3&lt;/span&gt;
&lt;span class="c1"&gt;#4&lt;/span&gt;
&lt;span class="c1"&gt;#5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a very simple example, but it does an effective job of manipulating the value of a variable to the desired number in only 1 line of easy to read code.&lt;/p&gt;

&lt;h1&gt;Concluison&lt;/h1&gt;

&lt;p&gt;The key to loops in Ruby, and any programming language really, is knowing what loop is best used in a given situation. Do you want to repeat an action a specific amount of times with little additional context? Use &lt;code&gt;times&lt;/code&gt;!. Want to drown someone special in your eternal love? Use &lt;code&gt;loop&lt;/code&gt; (with no &lt;code&gt;break&lt;/code&gt;!)! Wanna get a little more complex with your code? Use &lt;code&gt;while&lt;/code&gt;! Need a simple and precise statement modifier? Use &lt;code&gt;until&lt;/code&gt;!&lt;/p&gt;

&lt;h1&gt;Loops Lab&lt;/h1&gt;

&lt;p&gt;Now that you've learned about &lt;code&gt;Loops&lt;/code&gt;, let's head on over to the &lt;a href="https://github.com/BMWeygant/Ruby-Tutorial-Loops-Lab"&gt;Ruby Loops Lab&lt;/a&gt; and apply those lessons by completing the assigned tasks.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Ruby Methods</title>
      <dc:creator>Brandon Weygant</dc:creator>
      <pubDate>Tue, 12 May 2020 20:54:50 +0000</pubDate>
      <link>https://dev.to/bmweygant/ruby-methods-ph</link>
      <guid>https://dev.to/bmweygant/ruby-methods-ph</guid>
      <description>&lt;p&gt;In previous lessons, we discussed variables and logic in Ruby. Today we're going to discuss methods, what they are, and how to define them among other things.&lt;/p&gt;

&lt;h1&gt;What are Methods in Ruby?&lt;/h1&gt;

&lt;p&gt;Methods are simply instructions for your program to follow when the method is called. If you compare the variables we learned about before to 'nouns', you could make the analogy methods are 'verbs'.&lt;/p&gt;

&lt;p&gt;The power of methods is only limited by one thing: the creator's imagination...ok there are &lt;em&gt;some&lt;/em&gt; technical limits as well, but you get me. They are powerful tools that allow you to customize and optimize your program to whatever means you seem fit. &lt;/p&gt;

&lt;p&gt;Probably the largest benefit to methods is the ability to store the action for later use. Unlike the types of variables and conditionals we used earlier, which run each time we run our program, methods will only run when they are called somewhere inside the program. &lt;/p&gt;

&lt;p&gt;An example of a method could be our "Sam Sees Ghost" example from an earlier lesson. Turning this into a method is as easy as wrapping our code in the &lt;code&gt;def&lt;/code&gt; (short for define) &amp;amp; &lt;code&gt;end&lt;/code&gt; keywords like so:&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;seeing_ghosts&lt;/span&gt; &lt;span class="c1"&gt;#Line 1 defines and names the method&lt;/span&gt;
    &lt;span class="n"&gt;sam_tds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; 
    &lt;span class="n"&gt;sam_ints&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="c1"&gt;#Line 2 &amp;amp; 3 Define our variables relevant to the method. &lt;/span&gt;
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;sam_tds&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;sam_ints&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"Jets win!!"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sam_ints&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"I'm seeing ghosts."&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Jets lose!!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
&lt;span class="c1"&gt;#In Line 4 we define the behavior(s) we want our program to make when this method is called&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt; &lt;span class="c1"&gt;#And finally, we close the method with the 'end' keyword.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's important to note we have to define our variables &lt;em&gt;inside&lt;/em&gt; the method. Method's have there own level of &lt;code&gt;Scope&lt;/code&gt;, which we will get deeper into in a later lesson. For now, just remember to define any variable you will need inside the method.&lt;/p&gt;

&lt;p&gt;Now our method won't run automatically, we have to call it somewhere else in our program. So let's add a call for our method right underneath it:&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;seeing_ghosts&lt;/span&gt;
    &lt;span class="n"&gt;sam_tds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
    &lt;span class="n"&gt;sam_ints&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; 
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;sam_tds&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;sam_ints&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"Jets win!!"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sam_ints&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"I'm seeing ghosts."&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Jets lose!!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;seeing_ghosts&lt;/span&gt; &lt;span class="c1"&gt;#=&amp;gt; I'm seeing ghosts.&lt;/span&gt;
&lt;span class="c1"&gt;#This is a call that will tell our program to run the 'seeing_ghosts' method&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And we've successfully turned our code into a method!&lt;/p&gt;

&lt;h1&gt;Arguments&lt;/h1&gt;

&lt;p&gt;The above method is great and all, but it is written in a way that assumes Sam is the only one who sees ghosts! If we wanted to introduce ways to see if Dak Prescott or Big Ben see ghosts, we would have to write entirely different methods for each one. As a programmer, and especially a Rubyist, I'm too lazy for that - and so should you be! Enter arguments.&lt;/p&gt;

&lt;p&gt;Arguments are a way to make our methods more dynamic and reusable. By adding in arguments and changing the hard-coded parts of our previous method, we can make it useful in a multitude of situations!&lt;/p&gt;

&lt;p&gt;As an added bonus, arguments will also allow us to access variables &lt;em&gt;outside&lt;/em&gt; of the method! For starters, let's see how our original &lt;code&gt;seeing_ghosts&lt;/code&gt; method looks with arguments:&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;sam_tds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="n"&gt;sam_ints&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;seeing_ghosts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ints&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;#The '()' after the method name denotes this method takes the arguments 'sam_tds' &amp;amp; 'sam_ints'. &lt;/span&gt;
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;sam_tds&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;sam_ints&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"Jets win!!"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sam_ints&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"I'm seeing ghosts."&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Jets lose!!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;seeing_ghosts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sam_tds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sam_ints&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;#=&amp;gt; I'm seeing ghosts.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Just like that, we have a method with 1/3 less fat on it and we will be able to use those variables elsewhere in our code without redefining them as well!&lt;/p&gt;

&lt;p&gt;But this method still discriminates against Sam, and I don't write code to only make Bills and Giants fans happy. So we will begin making this method a bit less Sam-specific (and use more conventional conditional logic):&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;seeing_ghosts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ints&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;tds&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ints&lt;/span&gt;
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"We win!!"&lt;/span&gt;
  &lt;span class="k"&gt;elsif&lt;/span&gt; &lt;span class="n"&gt;ints&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; 
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"I'm seeing ghosts."&lt;/span&gt;
  &lt;span class="k"&gt;else&lt;/span&gt;
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"We lose!!"&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; You can name your arguments anything, but try to keep a good sense of abstraction to make them easier to read. Here I decided &lt;code&gt;tds&lt;/code&gt; &amp;amp; &lt;code&gt;ints&lt;/code&gt; were specific enough so we could all understand what we are trying to do in the method.&lt;/p&gt;

&lt;p&gt;This method will allow us the flexibility to enter either the number of &lt;code&gt;tds&lt;/code&gt;/&lt;code&gt;ints&lt;/code&gt; manually or place any defined variables from our code:&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;sam_tds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="n"&gt;sam_ints&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;

&lt;span class="n"&gt;seeing_ghosts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sam_tds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;sam_ints&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; I'm seeing ghosts.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Will work the same as:&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;seeing_ghosts&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="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; I'm seeing ghosts.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;Default Arguments&lt;/h1&gt;

&lt;p&gt;This method is &lt;em&gt;pretty&lt;/em&gt; close to what we had in the last lesson, but we did have to cut out the team name to make it fit any QB. How can we call methods powerful if it just forces us to stupify our code and make it more generic?&lt;/p&gt;

&lt;p&gt;The simple answer: it doesn't. We can add another argument called &lt;code&gt;team&lt;/code&gt;, specify the team the QB plays for, and then use our old friend string interpolation! So let's do it!&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;seeing_ghosts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ints&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;team&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;tds&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ints&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;team&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; win!!"&lt;/span&gt;
  &lt;span class="k"&gt;elsif&lt;/span&gt; &lt;span class="n"&gt;ints&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; 
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"I'm seeing ghosts."&lt;/span&gt;
  &lt;span class="k"&gt;else&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;team&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; lose!!"&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;seeing_ghosts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;7&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="s2"&gt;"Eagles"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; Eagles win!!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's great and all, but as a Jets fan, I spend most of my time talking about and caring about the Jets. I don't want to type the team name every time if I don't have to. People should know I'm talking about the Jets by default, right?&lt;/p&gt;

&lt;p&gt;Right!&lt;/p&gt;

&lt;p&gt;You can set a default value that will automatically be passed if you choose not to specify a value for that argument! So lets set &lt;code&gt;team&lt;/code&gt; to equal "Jets" by default!:&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;seeing_ghosts&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;tds&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ints&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;team&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"Jets"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;tds&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ints&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;team&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; win!!"&lt;/span&gt;
  &lt;span class="k"&gt;elsif&lt;/span&gt; &lt;span class="n"&gt;ints&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; 
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"I'm seeing ghosts."&lt;/span&gt;
  &lt;span class="k"&gt;else&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;team&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; lose!!"&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="n"&gt;seeing_ghosts&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;0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="c1"&gt;#=&amp;gt; Jets win!!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is no limit to the number of arguments you can assign a default value. We could add a &lt;code&gt;name&lt;/code&gt; argument and set the default to &lt;code&gt;= "He"&lt;/code&gt; for a generic QB quote like &lt;code&gt;"#{name} is seeing ghosts."&lt;/code&gt; and a whole bunch more customizable options. &lt;/p&gt;

&lt;h1&gt;Methods Lab&lt;/h1&gt;

&lt;p&gt;When you're finished reviewing this lesson, head over to the &lt;a href="https://github.com/BMWeygant/Ruby-Tutorial-Methods-Lab"&gt;Ruby Methods Lab&lt;/a&gt;, and complete all the tasks given. Have fun and good luck!&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Common Ruby Operators and Conditional Logic</title>
      <dc:creator>Brandon Weygant</dc:creator>
      <pubDate>Fri, 08 May 2020 18:38:43 +0000</pubDate>
      <link>https://dev.to/bmweygant/common-ruby-operators-and-conditional-logic-25pa</link>
      <guid>https://dev.to/bmweygant/common-ruby-operators-and-conditional-logic-25pa</guid>
      <description>&lt;p&gt;This week I'm going to be covering common Ruby Operators (specifically the Comparison, common Boolean, and Ternary Operators) and an Introduction into Conditional Logic in Ruby as well.  &lt;/p&gt;

&lt;h1&gt;Booleans in Ruby&lt;/h1&gt;

&lt;p&gt;Firstly, let us get an idea of what a boolean is in Ruby. A boolean in Ruby is simply something that refers to a value of &lt;code&gt;true&lt;/code&gt; or &lt;code&gt;false&lt;/code&gt;. Unlike some other programming languages, Boolean is not its own class in Ruby. Instead Ruby has the &lt;a href="https://ruby-doc.org/core-2.5.0/TrueClass.html"&gt;TrueClass&lt;/a&gt; and the &lt;a href="https://ruby-doc.org/core-2.5.0/FalseClass.html"&gt;FalseClass&lt;/a&gt; which for this lesson should be an adequate explanation. Read the supplementary material linked for more info. &lt;/p&gt;

&lt;h1&gt;The Common Ruby Operators&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;== aka The Comparison Operator:&lt;/strong&gt; In the previous lesson we learned the &lt;code&gt;=&lt;/code&gt; operator is used to declare a variable to a value. Ruby also boasts an operator &lt;code&gt;==&lt;/code&gt; which is used to compare values and return &lt;code&gt;true&lt;/code&gt; if both are equal.&lt;br&gt;
Example:&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="o"&gt;==&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="c1"&gt;#=&amp;gt; true &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Whereas&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="o"&gt;==&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="c1"&gt;#=&amp;gt; false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;"!" aka The "Single-Bang" Operator&lt;/strong&gt; &lt;code&gt;!&lt;/code&gt; stands for "NOT". It's mainly used to manipulate something that is &lt;code&gt;true&lt;/code&gt; into something that is &lt;code&gt;false&lt;/code&gt; and vice versa.&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;2&lt;/span&gt; &lt;span class="c1"&gt;#=&amp;gt; true&lt;/span&gt;
&lt;span class="nb"&gt;puts&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;#=&amp;gt; false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;"&amp;amp;&amp;amp;" aka The "AND" operator&lt;/strong&gt; The &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; operator is used to tie 2 or more conditionals together. All values have to be true to be read as &lt;code&gt;true&lt;/code&gt;.&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="kp"&gt;true&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt; &lt;span class="c1"&gt;#=&amp;gt; true&lt;/span&gt;
&lt;span class="kp"&gt;true&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt; &lt;span class="c1"&gt;#=&amp;gt; false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;"||" aka The "OR" Operator&lt;/strong&gt; Like the &lt;code&gt;&amp;amp;&amp;amp;&lt;/code&gt; Operator the &lt;code&gt;||&lt;/code&gt; Operator is also used to tie 2 or more conditionals together. The difference is only 1 of the conditionals has to be true to read as &lt;code&gt;true&lt;/code&gt;.&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="kp"&gt;true&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="kp"&gt;true&lt;/span&gt; &lt;span class="c1"&gt;#=&amp;gt; true&lt;/span&gt;
&lt;span class="kp"&gt;true&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="kp"&gt;false&lt;/span&gt; &lt;span class="c1"&gt;#=&amp;gt; true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;"if", "elsif", and "else" in Ruby&lt;/h1&gt;

&lt;p&gt;&lt;code&gt;if&lt;/code&gt;, &lt;code&gt;elsif&lt;/code&gt;, and &lt;code&gt;else&lt;/code&gt; all basically do the same thing: they tell the program to evaluate the proceeding conditional and if true to follow specific instructions. The most significant difference is where they are in an &lt;code&gt;if\else&lt;/code&gt; statement. The following is the basic construct of an &lt;code&gt;if\else&lt;/code&gt; statement 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="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;condition_is_true&lt;/span&gt;
  &lt;span class="n"&gt;instruction1&lt;/span&gt;
&lt;span class="k"&gt;elsif&lt;/span&gt; &lt;span class="n"&gt;condition_above_is_false_check_this_and_if_true&lt;/span&gt;
  &lt;span class="n"&gt;instruction2&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
  &lt;span class="n"&gt;instruction3&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice &lt;code&gt;else&lt;/code&gt; has no conditional? In most cases &lt;code&gt;else&lt;/code&gt; is meant to capture all other circumstances not caught by the preceding conditions and you can ignore specifics and just put instructions.&lt;/p&gt;

&lt;p&gt;Also, note &lt;code&gt;elsif&lt;/code&gt; is spelled funny. This is a rare moment where I feel Ruby tried &lt;em&gt;too hard&lt;/em&gt; to simplify things for devs, as this is just silly grammar. &lt;/p&gt;

&lt;p&gt;Lastly, make sure to close out your conditionals with &lt;code&gt;end&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;And now, we can proceed to this week's example...&lt;/p&gt;

&lt;h1&gt;Sam Sees Ghosts&lt;/h1&gt;

&lt;p&gt;New York Jets Quarterback Sam Darnold is unfortunately judged far too harshly based on his "I'm seeing ghosts," game vs. New England. Outside of that 2 game stretch vs. NE and Jacksonville, he actually was really good!&lt;/p&gt;

&lt;p&gt;But Sam did confess to seeing ghosts, and as such we as programmers have to acknowledge this truth in our code somehow. First, we can start by defining Sam's interceptions and touchdowns against NE.&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;sam_ints&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;
&lt;span class="n"&gt;sam_tds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It was a terrible game.&lt;/p&gt;

&lt;p&gt;Next, we will put our first &lt;code&gt;if&lt;/code&gt; statement:&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="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;sam_tds&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;sam_ints&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Jets win!!"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Obviously, this will output nothing in our console as &lt;code&gt;sam_tds&lt;/code&gt; are less than &lt;code&gt;sam_ints&lt;/code&gt;. So we need a condition that will output something when Sam has more INT's than TD's:&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="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;sam_tds&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;sam_ints&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Jets win!!"&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt; 
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Jets lose!!"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="c1"&gt;# Will return "Jets lose!!" in the console.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great, so we have a condition to display in our console, but just losing is not quite the same as seeing ghosts, is it? Let's modify our logic and add a third conditional in there so Sam will let us know when he's seeing ghosts.&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="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;sam_tds&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;sam_ints&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Jets win!!"&lt;/span&gt;
&lt;span class="k"&gt;elsif&lt;/span&gt; &lt;span class="n"&gt;sam_ints&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;sam_tds&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Jets lose!!"&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;sam_ints&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;
  &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"I'm seeing ghosts!"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="c1"&gt;# Will return "Jets lose!!" in the console.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Ok, what happened? Sam does have 4 or more int's so why wasn't that displayed? In Conditional Logic, the first conditional that processes as "true" will be the output. Since we cover all possible outcomes in our first two conditions, that is what will be read. For this reason, your more specific conditions should be higher up the logical ladder.&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="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;sam_ints&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; 
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"I'm seeing ghosts."&lt;/span&gt;
&lt;span class="k"&gt;elsif&lt;/span&gt; &lt;span class="n"&gt;sam_ints&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;sam_tds&lt;/span&gt;
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Jets win!!"&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;sam_ints&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;sam_tds&lt;/span&gt;
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Jets lose!!"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="c1"&gt;# Will return "I'm seeing ghosts." in the console.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With this, Sam can now see ghosts. However, what if Sam has 4 INT's, but 7 TD's? It's likely the Jets won that game, but Sam is still seeing ghosts. How do we help Sam bust these ghosts? We could just switch the &lt;code&gt;if&lt;/code&gt; and &lt;code&gt;elsif&lt;/code&gt; conditionals and instructions, and that's totally fine!  Instead, we're going to use the "&amp;amp;&amp;amp;" to add an extra condition so our ghosts don't ruin Sam's gutsy performance.&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;sam_ints&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;
&lt;span class="n"&gt;sam_tds&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;7&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;sam_ints&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;sam_ints&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;sam_tds&lt;/span&gt;
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"I'm seeing ghosts."&lt;/span&gt;
&lt;span class="k"&gt;elsif&lt;/span&gt; &lt;span class="n"&gt;sam_ints&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;sam_tds&lt;/span&gt;
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Jets win!!"&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt; &lt;span class="n"&gt;sam_ints&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;sam_tds&lt;/span&gt;
    &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"Jets lose!!"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="c1"&gt;# Will return "Jets win!!" in the console.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This gives us a much better grip over the flow control of when Sam sees ghosts.&lt;/p&gt;

&lt;h1&gt;The Ternary Operator&lt;/h1&gt;

&lt;p&gt;A convenient little operator for some simple Conditional Logic, the Ternary operator allows us to assign one value if a condition is true and another if a condition is false.&lt;/p&gt;

&lt;p&gt;We write the Ternary Operator in this pattern:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;conditional ? action_if_true : action_if_false&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So the statement&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="n"&gt;sam_ints&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;sam_tds&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"I'm seeing ghosts."&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"I'm not seeing ghosts."&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Will produce the same result as the &lt;code&gt;if/else&lt;/code&gt; statement:&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="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;sam_ints&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="n"&gt;sam_tds&lt;/span&gt;
   &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"I'm seeing ghosts."&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
   &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"I'm not seeing ghosts."&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nice! The Ternary Operator allowed us to write shorter, more condensed code. But we had 3 possible outcomes in our example. Can we write code using the Ternary Operator that captures more than 2 values?&lt;/p&gt;

&lt;h1&gt;Bonus Ternary Lesson!&lt;/h1&gt;

&lt;p&gt;It's possible to manipulate your code to use the Ternary Operator for more than 2 expressions. This isn't very advisable in a pro setting, as it can get messy quickly and very difficult for other programmers to read. BUT in a code challenge setting combining what might take 6 lines into 1 line can feel like a major win in itself!.&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="n"&gt;sam_tds&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;sam_ints&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"Jets win!!"&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sam_ints&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="s2"&gt;"I'm seeing ghosts."&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="s2"&gt;"Jets lose!!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And voila! With the code above we can do everything our completed &lt;code&gt;if/else&lt;/code&gt; statement can do in 1 line.&lt;/p&gt;

&lt;h1&gt;Conditionals Lab&lt;/h1&gt;

&lt;p&gt;When you're finished reviewing this lesson, head over to the &lt;a href="https://github.com/BMWeygant/ruby-tutorial-conditionals-lab"&gt;Ruby Conditionals Lab&lt;/a&gt;, and complete all the tasks given. Have fun and good luck!&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Ruby Variables and String Interpolation</title>
      <dc:creator>Brandon Weygant</dc:creator>
      <pubDate>Mon, 04 May 2020 15:01:44 +0000</pubDate>
      <link>https://dev.to/bmweygant/ruby-variables-and-string-interpolation-5h6</link>
      <guid>https://dev.to/bmweygant/ruby-variables-and-string-interpolation-5h6</guid>
      <description>&lt;p&gt;So I decided to put together a series of class-style tutorials to teach my friends a little bit about Ruby. This is meant to be a series of tutorials, designed to be as basic of an introduction to Ruby as I can manage. Hope you all enjoy it. &lt;/p&gt;

&lt;p&gt;Also, there's a better than 0% chance the student was high...&lt;/p&gt;

&lt;p&gt;&lt;iframe src="https://player.vimeo.com/video/414320397" width="710" height="399"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h2&gt;Variable Lab&lt;/h2&gt;

&lt;p&gt;When you're done watching the video and feel confident you can test your skills with the &lt;a href="https://github.com/BMWeygant/ruby-tutorial-variables"&gt;Ruby Tutorial - Variables Lab&lt;/a&gt;. Follow the instructions in README.md to clone the lab to your machine, and how to submit it when done. This guide assumes you have Ruby installed on your machine and a Github account already in place.&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>ruby</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Job Hunting: Impressionable Company Rejections</title>
      <dc:creator>Brandon Weygant</dc:creator>
      <pubDate>Wed, 22 Apr 2020 20:28:11 +0000</pubDate>
      <link>https://dev.to/bmweygant/job-hunting-impressionable-company-rejections-1120</link>
      <guid>https://dev.to/bmweygant/job-hunting-impressionable-company-rejections-1120</guid>
      <description>&lt;p&gt;So if you've ever applied for a job, you've probably experienced quite a few rejections. Most of these rejections are not memorable in the least and quickly fade away. Others stick out and can actually shape the perception of your entire job hunt and whether it was a good or bad experience. So let's talk about a few (anonymous) rejections that stand out for me.&lt;/p&gt;

&lt;h1&gt;The Best Rejection&lt;/h1&gt;

&lt;p&gt;I got an interview through a mutual contact with a local company and the founder and lead developer were very eager to help me launch my career, but unfortunately my skill set didn't match up with what they were looking for at the time. After explaining this to me the founder still took the time to introduce me to the entire present staff and offered me an opportunity to work on my projects inside the company office (it has it's own coffee house!). Rejection and all, it was inspiring to meet a team willing to help put however they could. &lt;/p&gt;

&lt;h1&gt;The Worst Rejection&lt;/h1&gt;

&lt;p&gt;I had applied for a job at a startup whose business is getting developers like me jobs. They took the opportunity to reject me as an employee AND recruit me as a customer in the same letter.  They explained my profile had been "flagged" as someone who could benefit from their program an proceeded with the sales pitch. Maybe they are right, but this wasn't the way to convince me.&lt;/p&gt;

&lt;p&gt;Now, there is absolutely nothing wrong with being a customer at a prospective or even current employer. It's really dope if you are actually! But I had never heard of this service prior to researching them and applying. I went to them for work, and they turn it around and made it a sales opportunity? This was a massive turnoff for me towards the company.&lt;/p&gt;

&lt;h1&gt;Everything in Between&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;1. The "we had discussed it internally, but I didn't know they actually posted a job yet" Conversation&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;This one was a trip, though the guy was really nice. I was the first applicant so I got a call, and the guy told me this and that what I had applied for wasn't even going to be close to the job description. HE informed me he was in the "gathering applications phase" and would get back to me. Never did.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. The "I've never heard of your school before" Conversation&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;I'm pretty sure the interviewer wanted to hear Flatiron School was an accredited college and not a coding boot camp. Is what it is.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. The Overly Positive Reinforcement Even Though We've Never Talked Rejection&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;These for me are some of my favorite. It's one thing to praise people over the phone or in an interview when you're actually interacting with that person. But the emails after initial application implying how great a developer I am while telling me no? There is nice and there is trying too hard. The icing on the cake is these rarely come with &lt;em&gt;any&lt;/em&gt; sort of feedback, only they are moving forward with someone else. At least the more neutral or negative ones let me know it's experience, quality, or tech stack even if they don't elaborate. Respect though. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Getting Ghosted After Initial Communication&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;It's one thing to be ignored off the rip after applying. It's another thing entirely to have a secondary non-interview interaction with the company and then get ghosted. Nothing like being asked to provide follow up information, providing asked for information, then never hearing back. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. The "We Rejected You Already But One Week Later We Schedule an Interview for You Anyway Only For You To Fail A Technical Assessment...In A Language You Never Claimed You Knew" Rejection&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;That's the story. Got an opportunity through my coding bootcamp Flatiron School, got rejected, got another interview anyway. Writing was on the wall when I asked "What language was this" and butchered my assessment of a piece of code presented to me. No hard feelings, as this was an enjoyable experience.  &lt;/p&gt;

&lt;h1&gt;Honorable Mention&lt;/h1&gt;

&lt;p&gt;**The Wait List - **Not technically a rejection, but, I've recently been wait-listed for the first time by a company I really would be excited to work for if the opportunity does arise. Getting wait-listed isn't inherently good or bad, there really are a number of good reasons why this could be, and there isn't any shame in being a companies 2nd (or even 12th) choice for an opportunity you want. Add in the impact of COVID-19 and there are even more reasons than ever why an employer may use a wait list. &lt;/p&gt;

&lt;p&gt;That said, the wait list is probably the least satisfying answer you could receive, especially because you most likely went &lt;em&gt;deep&lt;/em&gt; in the interview process with the company. There is at least closure with being rejected, even if it may hurt more initially.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Advice:&lt;/strong&gt; In your initial bout with the total lack of closure you will likely experience, try to avoid asking "why?", to both yourself and the employer. There isn't really a satisfactory answer that will make you feel better &lt;em&gt;and&lt;/em&gt; you will still be on the wait list &lt;em&gt;at best&lt;/em&gt;. The employer has a right to there process, and while they likely &lt;strong&gt;wouldn't&lt;/strong&gt; hold the inquiry against you, coming off as understanding and respectful of their process is less likely to get you knocked down (or off!) that wait list.&lt;/p&gt;

&lt;h1&gt;Conclusion&lt;/h1&gt;

&lt;p&gt;No rejection is entirely pleasant or satisfying, not even the office space offer I got before. Dealing with rejection, in all it's forms, is one of the key challenges in any job hunt. Think of it like this: Giving up because of how a company rejected you &lt;em&gt;probably&lt;/em&gt; means the company was right not to hire you in the first place. Cold, but true.&lt;/p&gt;

&lt;p&gt;These are just my experiences, and I am 100% certain they are very tame by comparison to some other stories. At the very least, I hope this means I have had some &lt;em&gt;relatable&lt;/em&gt; experiences, if not exceptional. Thanks for reading and feel free to share your rejection stories below!&lt;/p&gt;

</description>
      <category>career</category>
    </item>
    <item>
      <title>Working (and Playing!) with RPG Maker MV</title>
      <dc:creator>Brandon Weygant</dc:creator>
      <pubDate>Wed, 15 Apr 2020 20:14:15 +0000</pubDate>
      <link>https://dev.to/bmweygant/working-and-playing-with-rpg-maker-mv-h3i</link>
      <guid>https://dev.to/bmweygant/working-and-playing-with-rpg-maker-mv-h3i</guid>
      <description>&lt;p&gt;So self-isolation affects us all differently. One of the biggest issues for me has personally been work/life balance. I'm either spending too much time being "productive" (or worrying if I'm being productive enough) or too much time doing recreational activities (recently put in about 40 hours into Fallout 4 in under a week) and neither state is good to be in. Add in that over the last 1.5 years I've been neglecting my creative side to learn new skills and pursue new job opportunities, and you have a 3 headed beast of unfulfillment I had been struggling to satiate. Insert into my life RPG Maker MV!&lt;/p&gt;

&lt;h1&gt;What is RPG Maker MV&lt;/h1&gt;

&lt;p&gt;RPG Maker MV(RPGMMV) is a software for developing 16-bit 2-d games, think SNES style of RPG's like &lt;a href="https://www.google.com/search?q=chrono+trigger+gameplay&amp;amp;tbm=isch&amp;amp;ved=2ahUKEwjSkpr59OroAhVGHN8KHbDyDU0Q2-cCegQIABAA&amp;amp;oq=chrono+trigger+gameplay&amp;amp;gs_lcp=CgNpbWcQAzICCAAyBggAEAgQHjIGCAAQCBAeMgYIABAIEB4yBAgAEBgyBAgAEBg6BAgAEENQyJgBWK2jAWC-pgFoAHAAeACAAUmIAZsEkgEBOZgBAKABAaoBC2d3cy13aXotaW1n&amp;amp;sclient=img&amp;amp;ei=nD6XXtLUOsa4_Aaw5bfoBA&amp;amp;bih=754&amp;amp;biw=1536"&gt;Chrono Trigger&lt;/a&gt;. Relative to many people's understanding of game development, RPGMMV does an excellent job streamlining the process and making it as simple as possible to make your own game. Map building is simple -even for the designed-ly challenged like myself-, character generation is very straight forward, and you can freely adjust your games database from items to battle mechanics to what the game will identify your stats as. It is a very thorough program even out of the box, with a couple of drawbacks.&lt;/p&gt;

&lt;h1&gt;The Limitations Out of The Box&lt;/h1&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Out of the box, it comes with a frustratingly limited amount of options and features, most noticeably when you try to build your first map. At first glance, the tilesets appear to be loaded with options, but you will quickly find they will never be able to fully realize your vision and are mostly for practice purposes. &lt;a href="https://forums.rpgmakerweb.com/index.php?threads/marus-mv-bits.46811/"&gt;PandaMaru&lt;/a&gt; has some good free tilesets for you to work with, but if you are anything like me you'll be considering searching for an artist to fully customize your in-game artwork.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Event/NPC creation has a steep learning curve compared to the other basic features of the game. This is relative though as RPGMV is development software and not a game, and any new software is bound to have a learning curve. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Character creation is a breeze, and it feels easier than it should be because the standard character parts don't allow you to create many unique looking characters (for my tastes anyway). I guess while simple, it does come off as uninspiring.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Other miscellaneous annoyances for me were how they made door generation an event rather than part of a tileset, the base tilesets don't really complete any modern/sci-fi theme, and my in-game tutorial was unreadable.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For me, none of these issues were deal-breakers, although if you go into this trying to bring an idea to life these hurdles can be an inspiration killer. My recommendation is to take that great idea you have for a game and put it on the back burner until you complete some tutorials and can get some basic/slightly advanced functions down in a practice project. &lt;/p&gt;

&lt;h1&gt;What's Not In The Box&lt;/h1&gt;

&lt;p&gt;The most appealing feature about RPGMMV is that despite the limitations out of the box, there are tons of opportunities to customize your game under the hood however you see fit. This is primarily done with plugins, which the dev community has made sure there is no shortage of. The underlying code in RPGMMV is JavaScript, and as such all plugins are written in JS as well. Plugins come in all shapes and sizes, from complete core system overwrites like to more complementary plugins that may enhance a single particular feature. Unless you are determined to make a game with only the basic components and features (or much less likely you have a severe deficiency in imagination/creativity), plugins will be some of the first things you research to expand your realm of possibilities. Fortunately, the software is very accepting of this and welcomes third party additions with open arms. The plugin manager tool has a very visible and accessible shortcut right in the main taskbar on top.&lt;/p&gt;

&lt;p&gt;Many plugins come with additional commands called note tags that can be used to access the game code and further customize specific features of the game. You place these note tags inside a box in the database called "Notes". For example, if you have Yanfly's "Level Up Growth Effects" plugin, you gain access to a nifty little note tag &lt;code&gt;&amp;lt;Level Up stat Growth: +x&amp;gt;&lt;/code&gt;. If you put this note tag in the notes box of a particular class in the Database under "Classes" and replace &lt;code&gt;stat&lt;/code&gt; with say &lt;code&gt;ATK&lt;/code&gt; and &lt;code&gt;x&lt;/code&gt; with &lt;code&gt;25&lt;/code&gt;, this will cause Attack to grow +25 per level up. There are hundreds of other note tags that are just as simple or way more complex, but each one allows you to customize your game as you see fit so you can stand out from the crowd even more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Side Lesson:&lt;/strong&gt; &lt;em&gt;The Notes box was originally designed to take notes in. Somewhere in RPG Maker's existence, some clever people realized they could access and alter game code through this box! And the revolution started from then on!&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;Some of the plugins I've found most useful can be found at these links (not all are free):&lt;br&gt;
&lt;a href="http://www.yanfly.moe/wiki/Category:Yanfly_Engine_Plugins"&gt;Yanfly&lt;/a&gt; - Yanfly has a massive library of plugins, but all of their plugins are designed around &lt;a href="http://www.yanfly.moe/wiki/Core_Engine_(YEP)"&gt;Yanfly's Core Engine&lt;/a&gt;, so make sure to install that before the other plugins to prevent compatibility issues.&lt;br&gt;
&lt;a href="http://sumrndm.site/mv-plugins/?fbclid=IwAR1yjxMhd0g53HWB3_Rg1Flz9DB3RB-ZcVuFxnNTOmaGDlHffgDLMQH9MEQ"&gt;SumRndmDde&lt;/a&gt; - In addition to these awesome plugins, this guy also has a great tutorial series &lt;a href="https://www.youtube.com/watch?v=IR9y6vco-VQ&amp;amp;list=PLMcr1s5MjsiTky6KB4ML-q_QoBE_ZYJk5&amp;amp;index=1"&gt;her&lt;/a&gt; to get you up and running quickly.&lt;/p&gt;

&lt;h1&gt;Conclusion&lt;/h1&gt;

&lt;p&gt;RPG Maker MV has been an awesome work/life balancer for me. It has been incredibly fun learning to develop games on this platform, and it has &lt;em&gt;just&lt;/em&gt; the right amount of tools available to help maintain and sharpen my existing skills in JS. It's a bit of a steep price when not on sale ($79.99 on Steam), but if you are at least semi-serious about game development as a hobby (or more) then it is worth the price as you will likely put more hours into this than a standard game and not even realize it.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Some Job Hunting Resources and Advice</title>
      <dc:creator>Brandon Weygant</dc:creator>
      <pubDate>Thu, 09 Apr 2020 18:50:03 +0000</pubDate>
      <link>https://dev.to/bmweygant/some-job-hunting-resources-and-advice-1c4c</link>
      <guid>https://dev.to/bmweygant/some-job-hunting-resources-and-advice-1c4c</guid>
      <description>&lt;h1&gt;General Advice and Observations&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Non-essential Skilled Job Posts Have All Upgraded Reqs&lt;/strong&gt;&lt;br&gt;
This may just be me or software/web development specifically, but I have noticed that many Junior/Entry level roles have gone away. Everything right now seems to be upgraded one level up. Senior roles are everywhere, and it is really hard to find a role that matches someone with less than 5 years of experience right now. This may be in part because a lot of jobs suddenly shifted to remote, and employers have always valued more experience in those roles. All I can say is keep applying anyway.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Networking From Home&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Probably the biggest shift in job-hunting is how networking has been effected. Now is a good time to connect and reinforce existing network contacts - even engaging non-professionally just to check-in. With meetups, conventions, and other group events on pause for a while, it gets very hard to expand your network by physically meeting new people.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;If anyone knows of any Virtual Job Fairs or Online Networking Sessions/Events (not LinkedIn or other social media) please let me know by commenting down below.&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Volunteer Opportunities&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There actually are some pretty unique volunteer opportunities to help gain some experience. For example New York is putting together a &lt;a href="https://www.ny.gov/programs/new-york-state-covid-19-technology-swat-team"&gt;Covid-19 SWAT Team&lt;/a&gt; and the White House Office of Science and Technology Policy has made a mass call out for tech experts to create a &lt;a href="https://www.whitehouse.gov/briefings-statements/call-action-tech-community-new-machine-readable-covid-19-dataset/"&gt;machine readable Covid-19 dataset&lt;/a&gt;. There is literally zero harm in checking out volunteer opportunities, and may actually be the best way to network in this crisis. &lt;/p&gt;

&lt;h1&gt;Resources&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;1. &lt;a href="https://candor.co/hiring-freezes/"&gt;Candor&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
Anybody who hasn't seen this crowd-sourced list yet should &lt;em&gt;really&lt;/em&gt; check it out. Easily the most helpful resource available. It tells you whether a company is hiring, in a hiring freeze, or laying off. It also tracks industry-specific statistics regarding how many companies in a said field are in a specified status.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. &lt;a href="https://docs.google.com/spreadsheets/d/1R9IR8Z3-gU8uf76HOvVvh44R-UeQAxzmDe03E_vwRfs/edit#gid=388136490"&gt;Remote Jobs in March Google Doc&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
This is a &lt;em&gt;massive&lt;/em&gt; list of remote jobs that were posted and available in the month of March (approximately 1589 jobs or so). I haven't been able to validate how many of these positions were frozen, changed, or removed as of today, but it is a resource worth checking out. The list is organized by company, contains a link to the job postings, and has several labels provided to each job for easy doc navigation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. &lt;a href="https://blog.powertofly.com/companies-still-hiring-during-covid-19-2645619431.html"&gt;Power to Fly&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
My favorite traditional blog article so far, this is a list of 28 well-known companies still hiring. Link's to each companies postings on &lt;a href="http://www.powertofly.com"&gt;www.powertofly.com&lt;/a&gt; where you can get more detailed info on each position.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. &lt;a href="https://news.ycombinator.com/item?id=22665398"&gt;Hacker News&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
A web sourced forum article that is worth taking a look at.&lt;/p&gt;

&lt;h1&gt;Conclusion&lt;/h1&gt;

&lt;p&gt;Just stay safe, be careful, and keep pressing forward. &lt;/p&gt;

</description>
      <category>career</category>
    </item>
  </channel>
</rss>
