<?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: Leigha</title>
    <description>The latest articles on DEV Community by Leigha (@leighad).</description>
    <link>https://dev.to/leighad</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%2F304636%2F40c92cfa-1b84-4585-b5ea-b88325e0715d.png</url>
      <title>DEV Community: Leigha</title>
      <link>https://dev.to/leighad</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/leighad"/>
    <language>en</language>
    <item>
      <title>ABSWIATH- a little inspiration for job seekers</title>
      <dc:creator>Leigha</dc:creator>
      <pubDate>Mon, 03 May 2021 21:53:08 +0000</pubDate>
      <link>https://dev.to/leighad/abswiath-a-little-inspiration-for-job-seekers-417m</link>
      <guid>https://dev.to/leighad/abswiath-a-little-inspiration-for-job-seekers-417m</guid>
      <description>&lt;p&gt;Wait- what the heck is that? Well, it's something that I've been saying to myself a lot lately: &lt;em&gt;Always Believe Something Wonderful Is About To Happen&lt;/em&gt;. &lt;/p&gt;

&lt;p&gt;I'm currently searching for my first engineering job after switching careers. I really don't need to say it, but it's tough out there! Some of you are probably in a similar situation, so this post is for you as much as it is for me. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Always Believe Something Wonderful Is About To Happen&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It's so easy to become discouraged when you haven't gotten that &lt;em&gt;YES&lt;/em&gt; yet. It is disappointing to make it through the first interview, only to be rejected at the second or third. It's tough to end up as second choice, knowing that you have to start the process all over again.  &lt;/p&gt;

&lt;p&gt;You already know that it can hard not to focus on these feelings. But, let's remember that it's important not to let them take over. Instead, try to turn that energy around to make it work for you. Stay positive, treat your mistakes as opportunities for growth, and remember that it just takes one yes!&lt;/p&gt;

&lt;p&gt;Don't take the rejections personally since there are so many reasons that decisions are made. Focus on what you can do to improve your next interview experience and avoid making assumptions as to why you didn't get the job. &lt;/p&gt;

&lt;p&gt;In life, you get out of it what you put into it. So, this means that you not only have to do the work, you must project your desires out into the universe. &lt;em&gt;Whoa, unicorn sprinkles alert!&lt;/em&gt; Seriously though, you have to put your energy out there to get what you want. Visualize yourself in your new role, as part of the team, contributing to the greater good of the world. You must stay positive and keep an open mind if you want good things to come. &lt;/p&gt;

&lt;p&gt;Although you may be feeling defeated at times, try to remain hopeful about what is yet to come. You will attract good things with your positive energy and then it is just a matter of time before something works out for you. &lt;/p&gt;

&lt;p&gt;Best of luck in your job search! Keep putting good energy into everything you do &amp;amp; don't forget to...&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Always Believe Something Wonderful Is About To Happen&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Safe Navigation Operator</title>
      <dc:creator>Leigha</dc:creator>
      <pubDate>Mon, 07 Dec 2020 05:06:31 +0000</pubDate>
      <link>https://dev.to/leighad/safe-navigation-operator-1dg0</link>
      <guid>https://dev.to/leighad/safe-navigation-operator-1dg0</guid>
      <description>&lt;h6&gt;
  
  
  Photo by &lt;a href="/photographer/zumberto-38564"&gt;Zumberto _&lt;/a&gt; from &lt;a href="https://freeimages.com/" rel="noopener noreferrer"&gt;FreeImages&lt;/a&gt;
&lt;/h6&gt;

&lt;p&gt;We can't function without operators in any language, and sometimes working with them can be a bit confusing. But, did you know that there are some lesser known operators in Ruby that can make your life easier? &lt;/p&gt;

&lt;p&gt;In this post I would like to explore the &lt;strong&gt;Safe Navigation Operator&lt;/strong&gt; a bit further. &lt;/p&gt;

&lt;p&gt;Lately I have been going through old projects to refactor, clean up my code, and get things &lt;em&gt;live&lt;/em&gt;. I have been noticing many places where this smooth operator would have been useful.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What exactly does it do?&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;The Safe Navigation Operator returns &lt;em&gt;nil&lt;/em&gt; if a method is called on a &lt;em&gt;nil&lt;/em&gt; object. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why should we care?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Well, it is best to avoid throwing errors at your users. It's not very nice! &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Let's take a look at a quick example:&lt;/em&gt;&lt;/strong&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;patch&lt;/span&gt; &lt;span class="s1"&gt;'/pizzas/:id'&lt;/span&gt; &lt;span class="k"&gt;do&lt;/span&gt;
        &lt;span class="vi"&gt;@pizza&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="no"&gt;Pizza&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;find_by&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;id: &lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:id&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="vi"&gt;@pizza&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="vi"&gt;@pizza&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;current_user&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="vi"&gt;@pizza&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;update&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;params&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:pizza&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
                &lt;span class="n"&gt;redirect&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s2"&gt;"/pizzas/&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="vi"&gt;@pizza&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;id&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
            &lt;span class="k"&gt;else&lt;/span&gt;
                &lt;span class="n"&gt;erb&lt;/span&gt; &lt;span class="ss"&gt;:'/pizzas/edit'&lt;/span&gt;
            &lt;span class="k"&gt;end&lt;/span&gt;
        &lt;span class="k"&gt;else&lt;/span&gt;
            &lt;span class="n"&gt;redirect&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="s2"&gt;"/pizzas"&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;In the snippet above, I am checking to see if there is indeed an instance of the Pizza class found by id, and if there is, does that instance's user match the current user?&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="vi"&gt;@pizza&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="vi"&gt;@pizza&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;current_user&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works just fine, but it would be cleaner to write:&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="vi"&gt;@pizza&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;user&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;current_user&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Why not use &lt;em&gt;.try&lt;/em&gt;? Well because that is provided by &lt;strong&gt;ActiveSupport&lt;/strong&gt; as part of &lt;em&gt;Ruby on Rails&lt;/em&gt;, which is awesome! However if you wish to remove this dependency, just use the Safe Navigation Operator instead of &lt;em&gt;.try&lt;/em&gt;.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Getting data quickly in Ruby</title>
      <dc:creator>Leigha</dc:creator>
      <pubDate>Sun, 29 Nov 2020 21:11:43 +0000</pubDate>
      <link>https://dev.to/leighad/getting-data-quickly-in-ruby-cgh</link>
      <guid>https://dev.to/leighad/getting-data-quickly-in-ruby-cgh</guid>
      <description>&lt;h6&gt;
  
  
  Photo by &lt;a href="/photographer/VanHeber-45289"&gt;Weber VanHeber&lt;/a&gt; from &lt;a href="https://freeimages.com/" rel="noopener noreferrer"&gt;FreeImages&lt;/a&gt;
&lt;/h6&gt;

&lt;p&gt;This mini post is a follow up to the &lt;em&gt;Hash-tastic!&lt;/em&gt; series. &lt;br&gt;
&lt;strong&gt;You can find it here:&lt;/strong&gt; &lt;a href="https://dev.to/leighad/hash-tastic-part-one-1706"&gt;https://dev.to/leighad/hash-tastic-part-one-1706&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In that series, I presented a nested data structure and discussed how to extract the data within it. I did not use any built in Ruby methods, but instead I chose to write all the code out for purposes of learning. &lt;/p&gt;

&lt;p&gt;Here I would like to show a quick and easy way to use a built-in Ruby method to pull out this data. While built-in methods are quite handy and certainly can save time and lines of code, it is really important to understand what is going on behind all that 'magic'. There are so many good ones to choose from, but for this example, we will look a bit closer at Ruby's &lt;strong&gt;values_at&lt;/strong&gt; method.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Say you have an array:&lt;/strong&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;arr&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'cat'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'dog'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'bird'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'fish'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'rabbit'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You could get multiple non-sequential values this way:&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="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arr&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="n"&gt;arr&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="n"&gt;arr&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or you could just use the &lt;strong&gt;values_at&lt;/strong&gt; method:&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="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;z&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;arr&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values_at&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;1&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would return the values of elements &lt;strong&gt;0, 1, 3&lt;/strong&gt; which are &lt;strong&gt;cat, dog, fish&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can also use &lt;strong&gt;values_at&lt;/strong&gt; with a hash:&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;candy_hash&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;gummies: &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;sours: &lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;chocolate: &lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here you could write:&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;candy_hash&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;values_at&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sours&lt;/span&gt;&lt;span class="p"&gt;:)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would return the value of &lt;strong&gt;sours:&lt;/strong&gt; which is &lt;strong&gt;7&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;As you can see, built-in methods can be quick and easy to use. It is tempting to grab one when you need that quick fix, but just make sure you really understand what is happening behind all that Ruby 'magic'!&lt;/p&gt;

</description>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Hash-tastic! part three</title>
      <dc:creator>Leigha</dc:creator>
      <pubDate>Sun, 22 Nov 2020 23:21:10 +0000</pubDate>
      <link>https://dev.to/leighad/hash-tastic-part-three-2hp4</link>
      <guid>https://dev.to/leighad/hash-tastic-part-three-2hp4</guid>
      <description>&lt;h6&gt;
  
  
  Photo by &lt;a href="/photographer/neopicture-53843"&gt;Joel Dietle&lt;/a&gt; from &lt;a href="https://freeimages.com/" rel="noopener noreferrer"&gt;FreeImages&lt;/a&gt;
&lt;/h6&gt;

&lt;p&gt;Hello again! I hope that so far you are learning to appreciate hashes and the power of nested data structures. Let's take a final look at our awesome bookshelf hash. In case you've forgotten what it looks like, parts 1 &amp;amp; 2 of this series have a lovely image for review. &lt;/p&gt;

&lt;p&gt;This time we'll be working with the last shelf, the Harry Potter bookshelf, a hash of hashes. We will go over how to output data from within this structure that is itself nested within the parent hash &lt;strong&gt;&lt;em&gt;bookshelf&lt;/em&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The desired output in this example is a sentence that displays to the user the book number (1st level key) and title (2nd level key) of every volume within the &lt;strong&gt;':harry_potter'&lt;/strong&gt; shelf.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Run the repl.it below to see how it works.&lt;/strong&gt;&lt;/p&gt;


&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@cdversiontwo/bookshelfhashexthree?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Here is a closer look at the magic that makes it happen:&lt;/strong&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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;print_potter_books&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;shelf&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="n"&gt;shelf&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;volume&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;info&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
    &lt;span class="n"&gt;info&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;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
      &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;k&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="ss"&gt;:title&lt;/span&gt; 
        &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="s2"&gt;"The title of &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="nb"&gt;name&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;volume&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 &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;."&lt;/span&gt;
        &lt;span class="nb"&gt;sleep&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="k"&gt;end&lt;/span&gt;
    &lt;span class="k"&gt;end&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;print_potter_books&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;bookshelf&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:harry_potter&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we take the &lt;strong&gt;':harry_potter'&lt;/strong&gt; &lt;em&gt;shelf&lt;/em&gt;, iterate  over it, taking each &lt;em&gt;volume&lt;/em&gt;, which contains &lt;em&gt;info&lt;/em&gt;, and then iterating over that &lt;em&gt;info&lt;/em&gt;, making a comparison against each &lt;em&gt;key&lt;/em&gt; inside the &lt;em&gt;info&lt;/em&gt; and if it matches, outputting the desired text containing data from two different layers of the hash. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; The &lt;em&gt;name&lt;/em&gt; method can be found on line 44 in the &lt;strong&gt;&lt;em&gt;repl.it&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Whew! If that was a bit much, just take a moment to read the code line by line. Try to think about the nested data structure like an onion and just peel away at it one layer at a time. &lt;/p&gt;

&lt;p&gt;For example, the code to show the user the date for Book 7 looks 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="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;bookshelf&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:harry_potter&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="ss"&gt;:book_7&lt;/span&gt;&lt;span class="p"&gt;][&lt;/span&gt;&lt;span class="ss"&gt;:date&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Puts out to the user:&lt;/strong&gt;&lt;br&gt;
2007&lt;/p&gt;

&lt;p&gt;Here it is easy to see the different levels of the data structure. The parent hash is &lt;strong&gt;&lt;em&gt;bookshelf&lt;/em&gt;&lt;/strong&gt; and to get to the date you must reach down three levels. &lt;/p&gt;

&lt;p&gt;Thanks for reading this far. If you didn't already know how awesome hashes and nested data structures are, hopefully now you do (at least a little bit)! &lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>ruby</category>
      <category>beginners</category>
    </item>
    <item>
      <title>React Redux final project- the journey continues</title>
      <dc:creator>Leigha</dc:creator>
      <pubDate>Wed, 16 Sep 2020 20:36:44 +0000</pubDate>
      <link>https://dev.to/leighad/react-redux-final-project-the-journey-continues-n1j</link>
      <guid>https://dev.to/leighad/react-redux-final-project-the-journey-continues-n1j</guid>
      <description>&lt;h6&gt;
  
  
  Photo by &lt;a href="/photographer/fish-30731"&gt;Bjarte  Kvinge Tvedt&lt;/a&gt; from &lt;a href="https://freeimages.com/" rel="noopener noreferrer"&gt;FreeImages&lt;/a&gt;
&lt;/h6&gt;

&lt;p&gt;What an exciting journey this has been so far! I am really proud of how much I have learned in just a few months. Let's keep this good energy going! &lt;/p&gt;

&lt;p&gt;I have been thinking about this final project for some time, and I have an idea I am quite excited about building. However, when project time came around, I found myself facing one of life's most difficult challenges. Before I go into the details of my final project, it is important to take a brief but sad detour. My sweet English Bulldog was nearing the rainbow bridge. We were advised to make final arrangements for her. So heavy was my mind and heart that I knew I had to change my idea- there was no other way I would be able to focus.&lt;br&gt;
&lt;em&gt;*see end notes for more...&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Now let's get happy again and talk about React and Redux- how much fun are they to play with? After swirling around while learning JavaScript for a spell, it was nice to put it to work using React's sensibly structured components. And Redux makes managing state less complicated by keeping one tidy store. Both libraries have documentation that is well-written and easy to follow. &lt;/p&gt;

&lt;p&gt;As much as I enjoy working with both, I would like to focus this post on some fundamentals of Redux. Although Redux is typically used to manage complex state, working with it in my final project was a great learning experience. &lt;br&gt;
Let's dig into some important things to remember when working with Redux. &lt;br&gt;
&lt;/p&gt;
  

&lt;p&gt;&lt;strong&gt;&lt;h3&gt;The three fundamental principles of Redux:&lt;/h3&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;Single Source of Truth&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Your app's global state is stored within an object tree 
inside a single store. This makes debugging easier.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;State is Read-only&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Actions are the only way to initiate a change of state. 
This prevents any unwanted changes to your app's state.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h3&gt;Changes are Made with Pure Functions&lt;/h3&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Reducers specify exactly how state should be transformed 
by these actions. 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;




&lt;blockquote&gt;
&lt;p&gt;Note: a pure function is one that produces the same output when given the same input and is free from side-effects (doesn't alter outside state).&lt;/p&gt;


&lt;/blockquote&gt;



&lt;br&gt;
Another thing that is critical to understand is Redux flow.
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;        Action ==&amp;gt; Reducer ==&amp;gt; Updated State
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;Actions are passed to the Reducer which initiates a change to State. &lt;br&gt;
Let's take a look at this lovely diagram for a better understanding. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpbt6oq9o1apyfsuu0lxf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpbt6oq9o1apyfsuu0lxf.png" alt="Alt Text" width="541" height="295"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;small&gt;&lt;a href="https://stackoverflow.com/questions/45416237/axios-calls-in-actions-redux" rel="noopener noreferrer"&gt;https://stackoverflow.com/questions/45416237/axios-calls-in-actions-redux&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;Here we can see in detail the flow of state change through Redux. The Store contains the current State which defines the user interaction that triggers an Action. The requested Action is sent to the Reducer using &lt;em&gt;dispatch()&lt;/em&gt; which takes the current State from the Store, applies the requested Action, and then returns a new, updated version of State. Please note that the State that is returned is actually a copy of the original State with the updates applied. Remember that State is never mutated- use of the &lt;em&gt;spread&lt;/em&gt; operator allows us to make a copy, apply the necessary changes, and return this updated State to the Store. To summarize:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Action creators are functions that return actions &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Actions are objects that have keys that include instructions that the Reducer uses to change State&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A Reducer is a function with a switch statement inside that receives instructions about how to change State using two arguments: &lt;br&gt;
&lt;em&gt;currentState&lt;/em&gt; and &lt;em&gt;action&lt;/em&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The Store in Redux is an object with two functions:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;em&gt;dispatch()&lt;/em&gt; initiates changes to State&lt;/li&gt;
&lt;li&gt;
&lt;em&gt;getState()&lt;/em&gt; gives access to the current State&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;



&lt;br&gt;
&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ffxrkpnnsjpbfps7d24dn.jpg" alt="Alt Text" width="639" height="426"&gt;

&lt;p&gt;*End notes: Tankie is actually doing much better- we ended up getting a second opinion and some hope. We also believe in the power of miracles. Thanks to everyone who sent good thoughts our way!&lt;/p&gt;

&lt;p&gt;Also- my new idea is such a good one that I will be writing a post all about it once I have finished working out my stretch goals. Please stay tuned for more!&lt;/p&gt;

&lt;h6&gt;
  
  
  Photo by &lt;a href="/photographer/cempey-44071"&gt;Cheryl Empey&lt;/a&gt; from &lt;a href="https://freeimages.com/" rel="noopener noreferrer"&gt;FreeImages&lt;/a&gt;
&lt;/h6&gt;

</description>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Tricky bits of JavaScript</title>
      <dc:creator>Leigha</dc:creator>
      <pubDate>Fri, 26 Jun 2020 15:59:21 +0000</pubDate>
      <link>https://dev.to/leighad/tricky-bits-of-javascript-515c</link>
      <guid>https://dev.to/leighad/tricky-bits-of-javascript-515c</guid>
      <description>&lt;h6&gt;
  
  
  Photo by &lt;a href="/photographer/artM-56112"&gt;artM&lt;/a&gt; from &lt;a href="https://freeimages.com/" rel="noopener noreferrer"&gt;FreeImages&lt;/a&gt;
&lt;/h6&gt;

&lt;p&gt;When learning a new language, it makes sense that some parts will seem kinda familiar while others are quite mysterious. I'm studying JavaScript now and there are a few tricky bits I'd like to review in more detail. &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      var, let, const  ◆  hoisting  ◆  scope  ◆  closure
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Before we go into the topics above, let's take a look into how JavaScript is working 'behind the scenes'. The JavaScript Engine actually makes two different passes over your code and in the first pass, called the Creation phase, the code is not executed line by line. Instead, a global object and an associated &lt;code&gt;this&lt;/code&gt; are created, and variables get set up in memory. During the second pass is where the work begins, called the Execution phase because this is when your code is actually run line-by-line and values are set to the variables previously defined and stored in memory during the first pass.  &lt;/p&gt;

&lt;p&gt;Having a good understanding of how the JavaScript engine actually evaluates your code is a valuable tool. This will be more evident as we explore the topics mentioned inside the box at the top of this post. &lt;/p&gt;




&lt;p&gt;Prior to the release of ES6, &lt;code&gt;var&lt;/code&gt; was the only choice for variable declaration. As it turns out, &lt;code&gt;var&lt;/code&gt; can cause some trouble in your code due to its flexible nature, and that is where &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; come to the rescue. Let's take a look at each variable declaration type a bit more closely.&lt;/p&gt;

&lt;p&gt;Before we go over &lt;code&gt;var&lt;/code&gt;, &lt;code&gt;let&lt;/code&gt;, and &lt;code&gt;const&lt;/code&gt;, it is important to review the concept of &lt;em&gt;scope&lt;/em&gt;. Scope is defined as "the current context of execution" and is basically where a variable is available to use. In the case of &lt;code&gt;var&lt;/code&gt;, it is function scoped when declared within a function and global scoped when declared outside a function. Function scoped means that the variable is accessible and available within that function only. This is quite different from global scoping where the variable becomes available to the entire window. &lt;br&gt;
Consider this example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;mood&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;happy&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

   &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;changeMood&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
     &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;newMood&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;curious&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
     &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;newMood&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="p"&gt;}&lt;/span&gt;

   &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;mood&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="nf"&gt;changeMood&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, the first variable declaration is within the global scope, so it is available for use anywhere within the window. When you &lt;code&gt;console.log(mood)&lt;/code&gt;, the output is 'happy', accessed from the global scope. &lt;/p&gt;

&lt;p&gt;The second variable declaration, inside the &lt;code&gt;changeMood()&lt;/code&gt; function, exhibits functional scope behavior. When &lt;code&gt;changeMood()&lt;/code&gt; is called, the output is 'curious' since the variable &lt;code&gt;newMood&lt;/code&gt; was declared within the function. It is available to the function itself, but if you tried to &lt;code&gt;console.log(newMood)&lt;/code&gt; from outside of the function, you get: &lt;code&gt;ReferenceError: newMood is not defined&lt;/code&gt;. The scope of &lt;code&gt;newMood&lt;/code&gt; is only within the &lt;code&gt;changeMood()&lt;/code&gt; function. &lt;/p&gt;

&lt;p&gt;In the case of &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt;, variable declarations using these keywords are block scoped only. This means that variable declarations can only be accessed within the block (inside the curly brackets only) from which they were declared. Keeping variable declarations out of the global scope helps to prevent bugs and issues with overwriting variables previously declared. &lt;/p&gt;

&lt;p&gt;Now that we've briefly covered &lt;em&gt;scope&lt;/em&gt;, let's take a look at some of the behaviors of &lt;code&gt;var&lt;/code&gt; that led to the need for &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt;. When you use &lt;code&gt;var&lt;/code&gt; to declare a variable, JavaScript won't prevent you from redeclaring that variable, in fact it won't even let you know that you have overwritten a previously declared variable. Oh no!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Coco&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Beebee&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cat&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;  &lt;span class="c1"&gt;//=&amp;gt; Beebee&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The output for &lt;code&gt;cat&lt;/code&gt; is 'Beebee' since &lt;code&gt;var&lt;/code&gt; allows for redeclaration of variables. This is an easy way to put bugs into your program and should be avoided. Take a look at how &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; prevent this down below:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Coco&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Coco&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Beebee&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;                &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;cat&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Beebee&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cat&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;                  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cat&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="s2"&gt;`SyntaxError: Identifier 'cat' has already been declared`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also note that &lt;code&gt;var&lt;/code&gt; and &lt;code&gt;let&lt;/code&gt; variables can be updated, whereas &lt;code&gt;const&lt;/code&gt; can only be defined once and may not be updated. &lt;/p&gt;




&lt;p&gt;Remember how the JavaScript engine processes your code in two passes? Good, let's put that knowledge to use. &lt;em&gt;Hoisting&lt;/em&gt; is defined as when variables and function declarations are 'moved' to the top of scope before execution. Well, they aren't really physically moved, but during the Creation phase they are set into memory and variables declared with &lt;code&gt;var&lt;/code&gt; are initialized with a value of &lt;code&gt;undefined&lt;/code&gt;. Variables declared with &lt;code&gt;let&lt;/code&gt; and &lt;code&gt;const&lt;/code&gt; are not initialized with a value, but are still set into memory. So if you try to use a variable with &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt; before it is declared, a &lt;code&gt;Reference Error&lt;/code&gt; occurs. Let's take a look at some examples:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;greeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hola&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Will be interpreted like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;var&lt;/span&gt; &lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//=&amp;gt; greeting is undefined&lt;/span&gt;
    &lt;span class="nx"&gt;greeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hola&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And when using &lt;code&gt;let&lt;/code&gt; or &lt;code&gt;const&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;  &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;         &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;greeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hola&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;          &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;greeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hola&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nl"&gt;ReferenceError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Cannot&lt;/span&gt; &lt;span class="nx"&gt;access&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;greeting&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="nx"&gt;before&lt;/span&gt; &lt;span class="nx"&gt;initialization&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;An interesting note about &lt;code&gt;const&lt;/code&gt;:&lt;br&gt;
Variables declared with &lt;code&gt;const&lt;/code&gt; must be initialized at the time of declaration.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;   &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
   &lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;greeting&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
   &lt;span class="nx"&gt;greeting&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;hola&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

   &lt;span class="nl"&gt;SyntaxError&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Missing&lt;/span&gt; &lt;span class="nx"&gt;initializer&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;declaration&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;So in summary:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;&lt;/th&gt;
&lt;th&gt;Scope&lt;/th&gt;
&lt;th&gt;Update?&lt;/th&gt;
&lt;th&gt;Re-declare?&lt;/th&gt;
&lt;th&gt;Hoisted?&lt;/th&gt;
&lt;th&gt;Initialized&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;var&lt;/td&gt;
&lt;td&gt;global or functional&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;td&gt;undefined&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;let&lt;/td&gt;
&lt;td&gt;block&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;const&lt;/td&gt;
&lt;td&gt;block&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;no&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;td&gt;required&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The last topic I would like to cover here is &lt;em&gt;closure&lt;/em&gt;. Closure is when an inner function is able to access the outer function's variables, creating a scope chain. This should make sense now that we understand &lt;em&gt;scope&lt;/em&gt; and &lt;em&gt;hoisting&lt;/em&gt;. The following example should be helpful:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;learn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;learning experience! &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;phrase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="p"&gt;){&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;learn&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nx"&gt;result&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;phrase&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Enjoy &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;your &lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;console&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;log&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;result&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;//=&amp;gt; Enjoy your learning experience! &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The innermost return of this function uses variables that have been declared outside of the inner function. This is possible because the scope chain is maintained by the inner function. When the function is executed, this scope chain allows access to the variables that live inside the outer function. This example would also work with &lt;code&gt;var&lt;/code&gt; (but don't!) and will not work with &lt;code&gt;const&lt;/code&gt; due to the need to initialize variables using &lt;code&gt;const&lt;/code&gt; at the time of declaration.&lt;/p&gt;

&lt;p&gt;Hopefully this helps to clarify some of the more mysterious parts of JavaScript functionality. Understanding these tricky parts will help you write better code! &lt;/p&gt;

</description>
      <category>codenewbie</category>
    </item>
    <item>
      <title>Putting it all together...</title>
      <dc:creator>Leigha</dc:creator>
      <pubDate>Wed, 10 Jun 2020 16:17:13 +0000</pubDate>
      <link>https://dev.to/leighad/putting-it-all-together-e78</link>
      <guid>https://dev.to/leighad/putting-it-all-together-e78</guid>
      <description>&lt;h6&gt;
  
  
  Photo by &lt;a href="/photographer/LuisFico-54510"&gt;Luis Francisco Cordero&lt;/a&gt; from &lt;a href="https://freeimages.com/" rel="noopener noreferrer"&gt;FreeImages&lt;/a&gt;
&lt;/h6&gt;

&lt;p&gt;This post is all about my first project using JavaScript with Rails as API!&lt;/p&gt;

&lt;p&gt;This was definitely the most challenging project for me so far. Up to this point, I have been using Rails for the front and back end of my apps, but now was the time to plunge into HTML, CSS, and JavaScript to do that work instead. Without too much prior practice, I made lots of mistakes and had to do a lot of refactoring (I didn't start out using Object Oriented JS initially- big mistake!). Overall, I really enjoyed working on this project and it sure has taught me a lot!&lt;/p&gt;

&lt;p&gt;Maybe you are having a similar experience so I would like to pass along a tip that was shared with me that I found to be quite helpful as I was working along on this project. Since I had already gotten kinda cozy with the rules and structure of Rails, it did take a moment to adjust to using JS on the front end. Before I heard this little JavaScript mantra, (please see credit below), I have to say that I felt a bit lost at times.&lt;br&gt;
We all know that’s no fun, so try to remember this:&lt;/p&gt;



&lt;p&gt;&lt;em&gt;&lt;strong&gt;When some event happens, I want to make what kind of fetch and then manipulate the DOM in what way?&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Event  ➤  Fetch  ➤  DOM manipulation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;So the event triggers, a fetch request is fired off, and then the DOM changes in some predetermined way. It seems so simple when you think of it like this but there is so much going on behind the scenes during this sequence.&lt;/p&gt;



&lt;p&gt;Consider this basic example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;    &lt;span class="kd"&gt;static&lt;/span&gt; &lt;span class="nf"&gt;categoryFormListener&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;categoryForm&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; 
          &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getElementById&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;category-form-container&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="nx"&gt;categoryForm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;submit&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
          &lt;span class="kd"&gt;function&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;preventDefault&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;categoryObject&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;group&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; 
              &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#group&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
            &lt;span class="nx"&gt;event&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;#group&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;""&lt;/span&gt;

            &lt;span class="nf"&gt;fetch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;CATEGORIES_URL&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;method&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;POST&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
                &lt;span class="na"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Content-Type&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;application/json&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
                &lt;span class="p"&gt;},&lt;/span&gt;
                &lt;span class="na"&gt;body&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; 
                 &lt;span class="nx"&gt;JSON&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;stringify&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;category&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nx"&gt;categoryObject&lt;/span&gt;&lt;span class="p"&gt;})&lt;/span&gt; 
            &lt;span class="p"&gt;})&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;res&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;res&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;json&lt;/span&gt;&lt;span class="p"&gt;())&lt;/span&gt;
            &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;then&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Category&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;json&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="nx"&gt;Category&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addCategoriesToDOM&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="p"&gt;})&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This class method is using &lt;code&gt;.addEventListener&lt;/code&gt; to listen for a 'submit' event. So we are waiting for the user to enter some information into the Category form and then click 'submit'.&lt;/p&gt;

&lt;p&gt;After this event has triggered ('submit' has been clicked), a fetch request is made to the &lt;code&gt;CATEGORIES_URL&lt;/code&gt;. This returns a promise that resolves to the response of that request. Response instances are returned when the &lt;code&gt;fetch()&lt;/code&gt; promises are resolved, successful or not. &lt;/p&gt;

&lt;p&gt;What exactly is a &lt;code&gt;promise&lt;/code&gt; though? According to MDN, The &lt;code&gt;Promise&lt;/code&gt; object represents the eventual completion (or failure) of an asynchronous operation and its resulting value. The resulting value will be parsed into JSON so then the data returned can be manipulated on the DOM and displayed to the user. It is the &lt;code&gt;json()&lt;/code&gt; method of the &lt;code&gt;Body&lt;/code&gt; mixin that takes a Response stream and reads it to completion. It then returns a promise that resolves with the result of parsing the body text as JSON.&lt;/p&gt;

&lt;p&gt;This JSON is then used to manipulate the DOM to render the desired result, in this case, creating a new Category.&lt;/p&gt;

&lt;p&gt;This is what the Category form looks like on the front end:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4sbr80o6u3xn47hgk1vz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F4sbr80o6u3xn47hgk1vz.png" alt="Alt Text" width="395" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  -&amp;gt;credit to &lt;em&gt;Ayana&lt;/em&gt;, thank you so much!
&lt;/h5&gt;

</description>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
    <item>
      <title>A Stitch in Time...</title>
      <dc:creator>Leigha</dc:creator>
      <pubDate>Wed, 06 May 2020 06:30:56 +0000</pubDate>
      <link>https://dev.to/leighad/a-stitch-in-time-33n</link>
      <guid>https://dev.to/leighad/a-stitch-in-time-33n</guid>
      <description>&lt;h6&gt;
  
  
  Photo by &lt;a href="/photographer/BeverlyLloydroberts-62109"&gt;Bev Lloyd-Roberts&lt;/a&gt; from &lt;a href="https://freeimages.com/" rel="noopener noreferrer"&gt;FreeImages&lt;/a&gt;
&lt;/h6&gt;

&lt;p&gt;For my first Rails project I created a knitting pattern sharing app where users can CRUD patterns as well as rate and comment on patterns. Even though there are tons of gems available that can make building your app much easier, I decided to write the code myself so that I could fully understand what was going on behind this ‘Rails magic’ I always hear about. It is pretty magical, but let’s acknowledge where that magic really comes from. Rails is the product of hard-working developers who have made our app creating journeys much easier, and for that I want to start off with a great big thank you!&lt;/p&gt;

&lt;p&gt;Working on this project has been really enriching and I’m looking forward to adding a few more features and improved functionality as well as some styling to this fun little app. At this stage, everything I have learned so far is coming together quite nicely and I am feeling more confident in my programming abilities. That being said, I still have points of total confusion mixed in with the oh-so-great feeling of getting things working successfully. But, I am smart enough to be aware that:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;“The more I learn, the more I realize how much I don't know.”&lt;/strong&gt;&lt;br&gt;
&lt;em&gt;Albert Einstein&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7mjjwvcqbdffrho6imfh.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2F7mjjwvcqbdffrho6imfh.jpg" alt="Alt Text" width="639" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  Photo by &lt;a href="/photographer/juliaf-55850"&gt;Julia Freeman-Woolpert&lt;/a&gt; from &lt;a href="https://freeimages.com/" rel="noopener noreferrer"&gt;FreeImages&lt;/a&gt;
&lt;/h6&gt;

&lt;p&gt;There are so many amazing parts and pieces to this project that I had a tough time narrowing down what I wanted to focus on for this blog. I could certainly talk about the MVC structure, or discuss nested routes or how to write validations or even go into detail about creating views. While all of this is incredibly important, I realized that the organized approach I took with this project ended up working out really well (surprise!) and that I want to emphasize that in case anyone needs to hear it. &lt;/p&gt;

&lt;p&gt;Before I even wrote one line of code, I made sure to clearly define my associations and the user story. I'll give you a peek here:&lt;/p&gt;

&lt;h4&gt;
  
  
  User story
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Users will be able to:
    -sign up, log in, log out

Users can:
    -CRUD patterns
    -rate and comment on patterns
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Wireframing (attributes and associations)
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    Models: User, Pattern, Comment

    User attributes:
        username
        email
        password_digest 

    User associations:
        has_secure_password
        has_many :patterns
        has_many :comments
        has_many :commented_patterns, through: :comments, source: :pattern

    Pattern attributes:
        pattern_name
        gauge
        level :integer
        instructions :text
        notes
        user_id

    Pattern associations:
        belongs_to :user
        has_many :comments
        has_many :users, through: :comments

    Comment attributes:
        rating :integer
        content :text
        user_id
        pattern_id 

    Comment associations:
        belongs_to :user
        belongs_to :pattern
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Having all of this clearly written out gave me solid direction for this project. What a big difference it makes! Like anything else in life, it pays to be organized and prepared. Something else I found really helpful was to break the project down into chunks that I could tackle day by day. In previous projects, I was overwhelmed at times thinking about all the pieces that needed to be done. This time though, since I gave myself reasonable amounts of work to do daily and I had some direction as to where I should be each day, I felt much less stressed and was able to focus on the joys of creating and the buzz of all that logic processing inside my brain.&lt;/p&gt;

&lt;p&gt;Before you go, I want to share something I discovered that I will &lt;strong&gt;definitely&lt;/strong&gt; be using next time: GitHub projects. Yes, I realize there are many wonderful apps for organizing your projects, but here’s the thing, you’re already working with GitHub (right?) so why not use their features? Not only will it help you stay on track and keep all your details together, you can also add GitHub functionality to your project board. Sadly I did not know about this great resource in time to use for this project, but I will be using it in the future, so I'll let you know how my experience went. Here's a tiny preview:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwk0zbrcyriajuifiv030.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fwk0zbrcyriajuifiv030.png" alt="Alt Text" width="800" height="404"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Thanks for reading and happy coding!&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>beginners</category>
      <category>rails</category>
    </item>
    <item>
      <title>The Sinatra Project: Pizza Hub</title>
      <dc:creator>Leigha</dc:creator>
      <pubDate>Mon, 30 Mar 2020 06:09:30 +0000</pubDate>
      <link>https://dev.to/leighad/the-sinatra-project-pizza-hub-1b5g</link>
      <guid>https://dev.to/leighad/the-sinatra-project-pizza-hub-1b5g</guid>
      <description>&lt;p&gt;Ahhhh- pizza! The combination of flavors and textures makes it the perfect comfort food. I must have been craving some because when it was time to choose a meaningful idea for a Collection Management System project, the choice was obvious- I would create an app using MVC and Sinatra ActiveRecord with full CRUD capabilities that would allow a user to create, read, update, and delete &lt;strong&gt;pizzas&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;How exciting! This was where I could put everything that I have learned so far into action. Although I would love to discuss every detail of this project since I had so much fun working on it, for the sake of time I will just highlight a few things I found to be notable.&lt;/p&gt;

&lt;p&gt;To start, I was delighted to hear about a gem called Corneal that would help me get this project going. Until this point, I had been building everything from scratch. It was really cool that when I initialized this project, Corneal took care of the basic scaffolding for my app. And since the general framework was already created, I was really able to focus on actualizing all of the ideas that I had swirling inside my imagination. &lt;/p&gt;

&lt;p&gt;As I was building this basic project, it was impressive that the Models are quite bare with the exception of inheriting from ActiveRecord::Base and the presence of a few powerful macros. The &lt;em&gt;has_many&lt;/em&gt; and &lt;em&gt;belongs_to&lt;/em&gt; relationships are established here, allowing for associations between users and pizzas as well as many methods made available through ActiveRecord. I used &lt;strong&gt;bcrypt&lt;/strong&gt; for password encryption, so the &lt;em&gt;has_secure_password&lt;/em&gt; macro was also included in my User class.&lt;/p&gt;

&lt;p&gt;In this project, I used:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;.create&lt;/em&gt; to &lt;strong&gt;create&lt;/strong&gt; a user or a pizza&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;.find_by_id&lt;/em&gt; and &lt;em&gt;.all&lt;/em&gt; to &lt;strong&gt;read&lt;/strong&gt; users or pizzas &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;.update&lt;/em&gt; to &lt;strong&gt;update&lt;/strong&gt; a pizza&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;em&gt;.destroy&lt;/em&gt; to &lt;strong&gt;delete&lt;/strong&gt; a pizza&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Stretch goal: add .update and .destroy functionality to User&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;It was helpful to keep in mind the flow of a Sinatra request and RESTful convention as I was building the routes within the Controllers.&lt;/p&gt;

&lt;p&gt;Building out the Views was quite interesting- I think &lt;strong&gt;.erb&lt;/strong&gt; is really neat and I have very little HTML and CSS experience. This is an area that I used up a lot of time playing around with small visual and functional details. Also, I did run into an issue regarding the use of a &lt;em&gt;textarea&lt;/em&gt; tag vs an &lt;em&gt;input&lt;/em&gt; tag with &lt;em&gt;type="text"&lt;/em&gt; inside the form used to create a pizza. In the case of the &lt;em&gt;input&lt;/em&gt; tag, the data entered by the user will populate into the form shown via the &lt;em&gt;'/pizzas/edit'&lt;/em&gt; route, but the data within the &lt;em&gt;textarea&lt;/em&gt; doesn't without the use of additional code. Any ideas?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Stretch goal: figure out how to get user data from textarea&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here is a look at the home page as shown when a User is logged in. The top nav bar is not shown if user not valid or logged in. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjkih8hqhbjcru1c2id0p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fjkih8hqhbjcru1c2id0p.png" alt="Alt Text" width="800" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To achieve that, I wrapped the nav bar code with the following inside the &lt;strong&gt;layout.erb&lt;/strong&gt; file:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;% if Helpers.logged_in?(session) %/&amp;gt;
       #html code for the nav bar 
&amp;lt;% end %&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;and the following inside the &lt;strong&gt;helpers.rb&lt;/strong&gt; file:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;def self.logged_in?(session)
    !!session[:user_id]
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Stretch goal: add full functionality for Ingredient MVC&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The code below was placed inside the User model to validate the presence of and uniqueness of both the User's user name and email:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;validates :user_name, presence: true, uniqueness: true
validates :email, presence: true, uniqueness: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This project is still under construction, even though at this point I have covered the basic requirements. A User can sign up, login, create, read, update, and destroy pizzas. A User must have a unique username and email, and can only update and destroy pizzas that belong to that User. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Stretch goal: improve styling and overall user experience&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Stay tuned for more updates as they happen!&lt;/p&gt;

&lt;h6&gt;
  
  
  Photo by &lt;a href="/photographer/pixaio-75844"&gt;pixaio&lt;/a&gt; from &lt;a href="https://freeimages.com/" rel="noopener noreferrer"&gt;FreeImages&lt;/a&gt;
&lt;/h6&gt;

</description>
      <category>codenewbie</category>
      <category>beginners</category>
      <category>ruby</category>
    </item>
    <item>
      <title>Hash-tastic! part two</title>
      <dc:creator>Leigha</dc:creator>
      <pubDate>Sun, 23 Feb 2020 02:37:40 +0000</pubDate>
      <link>https://dev.to/leighad/hash-tastic-part-two-45p7</link>
      <guid>https://dev.to/leighad/hash-tastic-part-two-45p7</guid>
      <description>&lt;h6&gt;
  
  
  Photo by &lt;a href="/photographer/alkat-43296"&gt;Alessandro Cattelan&lt;/a&gt; from &lt;a href="https://freeimages.com/" rel="noopener noreferrer"&gt;FreeImages&lt;/a&gt;
&lt;/h6&gt;

&lt;p&gt;Welcome back! I bet you're ready to dig a bit deeper into our awesome bookshelf hash. We are going to take a closer look at accessing information from a variety of nested data structure types. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Let's get started by checking out that lovely hash again:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzh9iymncq0yk2fuk317z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzh9iymncq0yk2fuk317z.png" alt="Alt Text" width="401" height="672"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By now you should be pretty familiar with the primary keys and the data type of the values each key returns. If not, no biggie! Just go back to part one and browse around a bit longer- sometimes it takes a moment for new concepts to really soak into that amazing brain. It's ok.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Run the repl.it below to see how to work further with this hash.&lt;/strong&gt;&lt;/p&gt;


&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@cdversiontwo/bookshelfhashextwo?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;


&lt;p&gt;Take some time to review the code for each example, noting how to access the desired values. We will go over each example in more detail below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Print the value of shelf one, a string, in uppercase:&lt;/strong&gt;&lt;br&gt;
This really just builds off of what we went over in the first post. Access the value of &lt;strong&gt;':shelf_one'&lt;/strong&gt; directly and convert that string to uppercase.&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;bookshelf&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:shelf_one&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;upcase&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"ENCYCLOPEDIAS"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;2. Access the value of shelf two, an array, and print the last element:&lt;/strong&gt;&lt;br&gt;
Here we are grabbing the value of &lt;strong&gt;':shelf_two'&lt;/strong&gt;, an array, and returning the last element.&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;bookshelf&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:shelf_two&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;last&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s2"&gt;"Star Atlas"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;3. Print each item in the array from shelf two:&lt;/strong&gt;&lt;br&gt;
Using the same array from &lt;em&gt;example 2&lt;/em&gt; above, puts each element out to the user. Note that the return value is the original array since we used &lt;strong&gt;'.each'&lt;/strong&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;bookshelf&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:shelf_two&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nf"&gt;each&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="nb"&gt;puts&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"World Maps"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Star Atlas"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Puts out to the user:&lt;/strong&gt;&lt;br&gt;
World Maps&lt;br&gt;
Star Atlas&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4. Print each key/value pair in the hash from shelf three:&lt;/strong&gt;&lt;br&gt;
The value of &lt;strong&gt;bookshelf[:shelf_three]&lt;/strong&gt; is a hash, this example shows how to puts each key/value pair out to the user. Return value is the original hash.&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;bookshelf&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:shelf_three&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;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;v&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;k&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:sci_fi&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="s2"&gt;"The Collection"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;:coloring_books&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="s2"&gt;"Mandalas"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Puts out to the user:&lt;/strong&gt;&lt;br&gt;
sci_fi: The Collection&lt;br&gt;
coloring_books: Mandalas&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5. Iterate over the hash of arrays from shelf four and list the key along with each value:&lt;/strong&gt;&lt;br&gt;
The value for the &lt;strong&gt;':shelf_four'&lt;/strong&gt; key is an array, and for this example the goal is to puts out to the user each element of the array as a value of the secondary key &lt;strong&gt;':sci_fi'&lt;/strong&gt;. For this to work, we must take an additional step to grab each value and put it out to the user along with the key. As you may have guessed, the return value is the original value 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="n"&gt;bookshelf&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="ss"&gt;:shelf_four&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;k&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;
   &lt;span class="n"&gt;v&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;v&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;k&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;: &lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="n"&gt;v&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
   &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="ss"&gt;:sci_fi&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"The Collection Two"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s2"&gt;"Fantasy"&lt;/span&gt;&lt;span class="p"&gt;]}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Puts out to the user:&lt;/strong&gt;&lt;br&gt;
sci_fi: The Collection Two&lt;br&gt;
sci_fi: Fantasy&lt;/p&gt;

&lt;p&gt;As you can see, working with hashes and nested data structures isn't as scary as it seems. Analyze each layer, take it step by step, and don't be afraid to play around with the structure to grab and manipulate data as you wish.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxv1d118990pjbcxl8iif.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fxv1d118990pjbcxl8iif.jpg" alt="Alt Text" width="640" height="480"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See you next time for the third and final part in this series!&lt;/p&gt;

&lt;h6&gt;
  
  
  Photo by &lt;a href="/photographer/spadbarnsf-50965"&gt;Göran Nyqvist&lt;/a&gt; from &lt;a href="https://freeimages.com/" rel="noopener noreferrer"&gt;FreeImages&lt;/a&gt;
&lt;/h6&gt;

</description>
      <category>codenewbie</category>
      <category>ruby</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Hash-tastic! part one</title>
      <dc:creator>Leigha</dc:creator>
      <pubDate>Sun, 23 Feb 2020 01:12:44 +0000</pubDate>
      <link>https://dev.to/leighad/hash-tastic-part-one-1706</link>
      <guid>https://dev.to/leighad/hash-tastic-part-one-1706</guid>
      <description>&lt;h6&gt;
  
  
  Photo by &lt;a href="/photographer/magri-36404"&gt;Márcia Rodrigues&lt;/a&gt; from &lt;a href="https://freeimages.com/" rel="noopener noreferrer"&gt;FreeImages&lt;/a&gt;
&lt;/h6&gt;

&lt;p&gt;For many of us, hashes can be intimidating. Just when you thought you had mastered arrays, here come hashes with their snazzy curly brackets and all that extra syntax. Such show-offs!&lt;/p&gt;

&lt;p&gt;Really though, as the information you are working with grows larger, it is important to be comfortable with accessing and manipulating data stored in collections. It will be common for you to see nested data structures of many types used: arrays of hashes, hashes of arrays, hashes of hashes, just to name a few. Looking at all that data packed away inside those nested brackets, curly and otherwise, can seem overwhelming and as a newbie you may be left feeling confused. Fear not! Hashes are your friends.&lt;/p&gt;

&lt;p&gt;Let's talk about hashes and how to break them down into understandable pieces. I like to think of hashes as well-arranged book shelves where the contents of each shelf can be organized into key/value pairs. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Take a few moments to really understand the following hash:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzh9iymncq0yk2fuk317z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fzh9iymncq0yk2fuk317z.png" alt="Alt Text" width="401" height="672"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It looks pretty complicated, but if you break it down piece by piece, you will see that it isn't as scary as you thought!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Run the repl.it below to see how to work with the first level of this hash.&lt;/strong&gt;&lt;/p&gt;


&lt;div class="ltag__replit"&gt;
  &lt;iframe height="550px" src="https://repl.it/@cdversiontwo/bookshelfhashexone?lite=true"&gt;&lt;/iframe&gt;
&lt;/div&gt;


&lt;p&gt;To reach into the first level of this hash so that you can view the contents of each shelf is easy! Just type the name of the hash with square brackets around the 'shelf', or key name. Like this: &lt;strong&gt;bookshelf[:shelf_name]&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Take a few minutes to check out the repl.it again and consider what type of data each shelf returns. Feel free to explore the code to gain a better understanding of this hash as we will be discussing it in more detail over the next two parts of this series.&lt;/p&gt;

&lt;p&gt;By the way- &lt;br&gt;
That last bit about the Harry Potter shelf is quite messy! No worries! We will take a look at how to better display that data in part three of this series.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt;&lt;br&gt;
I did want to discuss the method on &lt;em&gt;line 44&lt;/em&gt; a little bit...&lt;br&gt;
As the hash is written, each first-level key is a symbol that includes an underscore which is not very pretty when put out to the user. To be more user-friendly, I needed to change &lt;strong&gt;':shelf_one'&lt;/strong&gt; to &lt;strong&gt;'Shelf one'&lt;/strong&gt; so that the sentence to be output to the user would make more sense. &lt;/p&gt;

&lt;p&gt;To do this, I first had to convert the symbol to a string with the &lt;strong&gt;.to_s&lt;/strong&gt; method. Then I used &lt;strong&gt;.capitalize&lt;/strong&gt; to capitalize the string, and then to take away that pesky underscore, I used &lt;strong&gt;.split('_')&lt;/strong&gt; and finally &lt;strong&gt;.join(' ')&lt;/strong&gt; to get the separate strings to behave as one. &lt;/p&gt;

&lt;p&gt;See you next time for part two in this series!&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>ruby</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to and not to do a CLI project-</title>
      <dc:creator>Leigha</dc:creator>
      <pubDate>Sat, 15 Feb 2020 21:36:29 +0000</pubDate>
      <link>https://dev.to/leighad/how-to-and-not-to-do-a-cli-project-3en9</link>
      <guid>https://dev.to/leighad/how-to-and-not-to-do-a-cli-project-3en9</guid>
      <description>&lt;h6&gt;
  
  
  Photo by &lt;a href="/photographer/patataj-41213"&gt;Patataj Patataj&lt;/a&gt; from &lt;a href="https://freeimages.com/" rel="noopener noreferrer"&gt;FreeImages&lt;/a&gt;
&lt;/h6&gt;

&lt;p&gt;So far, the first module in the Flatiron online program has been really fun and at times overwhelming. There is just &lt;strong&gt;so much useful information&lt;/strong&gt; to learn! I'm pretty excited to be at the point where we are taking everything we have practiced so far and are putting it all together in our first project: create a CLI Gem.&lt;/p&gt;

&lt;p&gt;My plan was to get started right away, which would give me over a week to work on the project. That would be ideal and is usually my approach. Well, plans don't always go through and as it turns out, I ended up only having a handful of days to work on this due to a family emergency. So I may have started off in a bit of a panic. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Challenge #1&lt;/strong&gt;&lt;br&gt;
I was now pressed for time and feeling unsure about being able to produce a nice product. I did not take time to think about the project itself much before I just dove into 'getting it done'.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Solution&lt;/em&gt;&lt;br&gt;
Before you approach a project, or really anything meaningful in life, you should take a moment to reflect on your intent. Try to visualize the process and focus on the final product. View any obstacles you may face as opportunities for growth. &lt;/p&gt;

&lt;p&gt;If I had just taken the time to really think about my project before getting started I could have saved myself a few wrong turns in the process.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Challenge #2&lt;/strong&gt;&lt;br&gt;
This wouldn't have been too much of an issue without problem #1. &lt;em&gt;I have no idea what I want to create!&lt;/em&gt; There are just too many possibilities and feeling pressed for time has temporarily clouded my creative abilities. Here is where I should have really put some thought into the design of my program. Sigh.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Solution&lt;/em&gt;&lt;br&gt;
Take time to carefully think about what you wish to achieve with your product. Pick something that is meaningful to you. What kind of functionality do you wish to create? Really think about the design of your interface so that it is pleasant to the user and make sure the project can be produced within the required timeframe. You can always expand on what you have built after you get your MVP going. &lt;/p&gt;

&lt;p&gt;So I decide on my lifetime standby topic: cats. I will create a CLI that scrapes fancy cats from a webpage and gives the user details about the cats.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frmnymemlcoeiz890na0p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frmnymemlcoeiz890na0p.png" alt="Alt Text" width="322" height="261"&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Challenge #3&lt;/strong&gt;&lt;br&gt;
This really builds off of problem #1 as well, and since I felt pressed for time, I did not give enough thought into choosing an appropriate site for scraping. After visiting a few sites, I found one that visually looked good and I started working on the scraping details. That site ended up being 'unscrapable' and I had to start all over again. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Solution&lt;/em&gt; &lt;br&gt;
Make sure that the site you select not only has the data you wish to gather, but also has the necessary information you need in order to access that data. The 'inspect' feature is your friend- use it to dig around on the page to make sure you can reach the data you want. I used &lt;strong&gt;repl.it&lt;/strong&gt; to help visualize finding the data I needed. Taking a few extra moments at this step will save you lots of time and headache in the future! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ft6oe90qd8ddngyo76o2z.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Ft6oe90qd8ddngyo76o2z.jpg" alt="Alt Text" width="639" height="425"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h6&gt;
  
  
  Photo by &lt;a href="/photographer/gmarcelo-47735"&gt;Marcelo Gerpe&lt;/a&gt; from &lt;a href="https://freeimages.com/" rel="noopener noreferrer"&gt;FreeImages&lt;/a&gt;
&lt;/h6&gt;

&lt;p&gt;I wasted some time at this step in terms of progress on this project, but I did learn a lot about scraping and what it takes to make a site 'scrapable'- valuable knowledge!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Challenge #4&lt;/strong&gt;&lt;br&gt;
I really can't emphasize that most of the issues I encountered with this project had to do with a lack of planning in the initial stages. I ended up having to redesign my interface a few times, and I don't think that would have been so much an issue if I had really thought it through before starting. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Solution&lt;/em&gt; &lt;br&gt;
The time it takes to plan your project is well worth every moment. &lt;/p&gt;

&lt;p&gt;After a few failed approaches, I ended up taking a break, setting up a solid plan, and then got to work. Although this project certainly is challenging, I found it much easier to create with a good plan in place. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fs19l2krncx8ixcbeusm8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fs19l2krncx8ixcbeusm8.png" alt="Alt Text" width="774" height="302"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Though I am still busy at work, I have been able to create a pleasant interface with the ability to fetch a list of fancy cat names and some history about each cat. There is also a feature to generate a random fun fact about one of the fancy cats. Currently, I am working on the code to generate lists of the most and least affectionate, energetic, and shedding cats. I'll post an update when I can!&lt;/p&gt;

</description>
      <category>codenewbie</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
