<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Claudia Maniscalchi on Medium]]></title>
        <description><![CDATA[Stories by Claudia Maniscalchi on Medium]]></description>
        <link>https://medium.com/@claudia.maniscalchi?source=rss-ff8525cbcc2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*BrSOptKLtxJVkUQ3BEXWJg.jpeg</url>
            <title>Stories by Claudia Maniscalchi on Medium</title>
            <link>https://medium.com/@claudia.maniscalchi?source=rss-ff8525cbcc2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 05:11:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@claudia.maniscalchi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Promised Messages]]></title>
            <link>https://medium.com/truthy-or-falsy/promised-messages-568845ae29de?source=rss-ff8525cbcc2------2</link>
            <guid isPermaLink="false">https://medium.com/p/568845ae29de</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Claudia Maniscalchi]]></dc:creator>
            <pubDate>Mon, 17 Dec 2018 04:58:34 GMT</pubDate>
            <atom:updated>2018-12-17T05:03:27.589Z</atom:updated>
            <content:encoded><![CDATA[<p>I recently learned about JavaScript’s async/await syntax, and was very taken with its eloquence; async functions and the await operator allow us to write code which <em>feels</em> like regular old synchronous javascript. I’ll go into the basics in this post by making use of a handy little mock-full-CRUD-API called <a href="https://jsonplaceholder.typicode.com/posts/">JSON Placeholder</a>, sending some Bob Dylan-themed messages off into the ether.</p><p>First, to illustrate the difference between async functions and standard functions, a simple GET request:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KYs8-jlnbJ9TZefNfjDHUQ.png" /></figure><p>Okay, nothing fancy there — I invoke getPosts, and console.log the result of my fetch request, which is a promise. Now, if I create a new function, this time with the termasync in front of my function delaration, the result is a little different:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QXuF1Z-c_b47uRp6ALBoJQ.png" /></figure><p>See what I did there? Async functions always return a promise, and you can see here, by making use of that one little word, the promise has been resolved, but I can’t yet access the results of that promise in a synchronous fashion. Right now, that promise is not doing me very much good, but if I modify it by making use of await, it’s another story.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*redtTOIkqqW56pvYzV7s9w.png" /></figure><p>Wow. I now have access to my actual array of posts. That worked, because the await operator forces JavaScript to wait for promises to resolve. Setting await fetch(url) equal to a variable allows me to directly access the evaluated fetch response in an array format. When previously I would have likely used a helper function as a workaround, I can access my data in a way that feels pretty familiar.</p><p>Now, to use another example, let’s make a POST request this time, using that old helper function, mentioned above. Without async/await it looks as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GOJb4zoSCpEjD9DNyW1cPg.png" /></figure><p>This is pretty standard asynchronous javascript. Let’s clean it up with async/await!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4rratVm1zXh4PF1Kt1ZBUQ.png" /></figure><p>Alternatively, I could easily chain a .then onto my response with the exact same result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*urxg8o25zirz61bPIv2prQ.png" /></figure><p>Note that I set the fetch request above equal to a variable, await the response, and then I can operate on that data by setting it equal to a new variable. In this example I need to use await again, otherwise that evaluated response would be (you guessed it) stuck within a promise once more.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k8NYp139RaDS5SeRL6R0tw.png" /></figure><p>I point this out to illustrate the fact that we can pass this object around like any other, just remember it’s <em>essential</em> to useawait.</p><p>Personally, I find async/await so nice and clean , and if this concept is new to you, I hope you do, too. I’m able to post to my API, evaluate the response, and access the data, all within one asynchronous function. Now, I can do whatever I please with the response!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=568845ae29de" width="1" height="1" alt=""><hr><p><a href="https://medium.com/truthy-or-falsy/promised-messages-568845ae29de">Promised Messages</a> was originally published in <a href="https://medium.com/truthy-or-falsy">Truthy or Falsy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DOM Manipulation fun with jQuery]]></title>
            <link>https://medium.com/truthy-or-falsy/dom-manipulation-fun-with-jquery-cc9ddeff1e16?source=rss-ff8525cbcc2------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc9ddeff1e16</guid>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Claudia Maniscalchi]]></dc:creator>
            <pubDate>Mon, 10 Dec 2018 04:58:54 GMT</pubDate>
            <atom:updated>2018-12-10T04:58:54.157Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I’ve been working on creating a modal from scratch, and I’ve taught myself jQuery in the process! For things like browser code snippets, jQuery makes your code so nice and clean. There are plenty of arguments for why <a href="https://css-tricks.com/now-ever-might-not-need-jquery/">you don’t need jQuery</a>, and sure, I could have done it without, but I’m pretty happy with the jQuery final product came out. Anything for the sake of learning, right?</p><p>I’m going to use NPR’s food blog <a href="https://www.npr.org/sections/thesalt/">The Salt</a> as the demo for my modal, and I want an image of (surprise) food to display when I scroll down on the page.</p><p>The first step: declaring where to trigger the modal to display. Let’s figure out where on the page we are by establishing some variables:</p><pre>let documentHeight = $(document).height()<br>let windowHeight = $(window).height()<br>let oneThirdHeight = parseInt(documentHeight * 1/3)</pre><p>We’re going to use those figures in combination with $(window).scrollTop(), which gets the current vertical position for the window. That one I’ve decided is best if not assigned to a variable, since its value is constantly changing based on the location of the user’s scrolling. When I set it to a variable, it was set to the vertical position of where I was when I declared it, and it didn’t automatically update on scrolling.</p><p>So, let’s say we want our modal to display when we’ve scrolled 2/3 down the page. We’re going to need some conditional logic:</p><pre>$(window).on(&#39;scroll&#39;, () =&gt; {<br>    if (documentHeight - windowHeight - $(window).scrollTop() &lt;= oneThirdHeight) {<br>      $(&#39;body&#39;).append(&#39;&lt;div&gt;&lt;/div&gt;&#39;)<br>      console.log(&#39;appended!&#39;)<br>    }<br>  })</pre><p>When we scroll down the page, we can see our console.log appear when we hit the 2/3 mark, and if we inspect the HTML… we can see the div has been successfully inserted, but it’s also inserted at <em>every</em> change in scroll height once we move beyond 2/3 of the way down the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/822/1*I4m9Sb_QflWWhpj3OgDIpg.png" /><figcaption>too many empty divs</figcaption></figure><p>To make sure a dive is inserted only once, I’m going to assign it an id, and add a bit more logic:</p><pre>$(window).on(&#39;scroll&#39;, () =&gt; {<br>  if (documentHeight - windowHeight - $(window).scrollTop() &lt;= oneThirdHeight &amp;&amp; $(&#39;#overlay&#39;).length === 0) {<br>    $(&#39;body&#39;).append(&#39;&lt;div id=&quot;overlay&quot;&gt;&lt;/div&gt;&#39;)<br>    console.log(&quot;appended only once, now&quot;)<br>  }<br>})</pre><p>Success — I’ve added a div with an id of ‘overlay’, and before it’s added, I’m checking that it doesn’t already exist in the DOM. The console.log displays only once, and the div is appended just one time.</p><p>Now I’m not going to go into the styling here, but essentially my modal is going to dim the background of the page, and I want a div to remain anchored in the center while I scroll. Here’s the gist of it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6qhQRIjKnKhrMorimTAlTQ.png" /></figure><p>My ‘overlay’ div now has two children divs: ‘overlay-container’ and ‘overlay-background’. The container div has two children of its own: ‘overlay-closer’ and ‘overlay-content’. The all get appended along with the parent div.</p><p>When I input my entire clippet into the console, this is what displays when I scroll down to my 2/3 mark:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*k-G-PAD72G0QLHAmAZoq7g.png" /><figcaption>empty modal</figcaption></figure><p>That’s a great start! Unfortunately, I don’t have a way to remove this modal at this point, so let’s add that functionality in, specifically to the $(‘body’).append(‘&lt;div id=”overlay”&gt;&lt;/div&gt;’) portion of our code.</p><pre>$(&#39;body&#39;).append(&#39;&lt;div id=&quot;overlay&quot;&gt;&lt;/div&gt;&#39;)<br>  .click((e) =&gt; {<br>    e.stopPropagation()<br>    if (e.target !== $(&#39;#overlay-content&#39;)[0]) {<br>      $(&#39;div#overlay&#39;).remove())<br>    }<br>  })</pre><p>There are a few things going on here:</p><ol><li>e.stopPropagation() is making sure that my click event doesn’t bubble up, i.e. my click is not triggering any duplicate actions.</li><li>I’m removing the entire overlay div <em>only</em> if I click outside of ‘overlay-content’, which is the white box in the screenshot above. To check for that, I’m using the built-inevent argument.</li></ol><p>Now, when I click outside of the modal, the modal closes. If I scroll down below the triggering location a second time, my modal will display again, because that div no longer exists.</p><p>To wrap up my modal’s functionality, I want to use some of jQuery’s built-in animations. I’m going to set my overylay div to hidden when I add it, then we I can set it to fade in. To remove it I’m going to take the reverse action — I’ll ghide the dive with an fade-out animation, and once it’s done fading out, then I’ll remove it from the DOM. This requires a bit of refactoring:</p><pre>$(&#39;&lt;div id=&quot;overlay&quot;&gt;&lt;/div&gt;&#39;).hide().appendTo($(&#39;body&#39;)).show(&#39;normal&#39;)<br>    .click((e) =&gt; {<br>      e.stopPropagation()<br>      if (e.target !== $(&#39;#overlay-content&#39;)[0]) {<br>        $(&#39;div#overlay&#39;).hide(&#39;normal&#39;, () =&gt; $(&#39;div#overlay&#39;).remove())<br>      }<br>    })</pre><p>Now, I have a fully functional modal, built 100% with DOM manipulation using jQuery. I’ll go into the CSS here in another post. Until then, happy jQuerying.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc9ddeff1e16" width="1" height="1" alt=""><hr><p><a href="https://medium.com/truthy-or-falsy/dom-manipulation-fun-with-jquery-cc9ddeff1e16">DOM Manipulation fun with jQuery</a> was originally published in <a href="https://medium.com/truthy-or-falsy">Truthy or Falsy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reduce-ing Clutter with JavaScript]]></title>
            <link>https://medium.com/truthy-or-falsy/reduce-ing-clutter-with-javascript-890a1873b325?source=rss-ff8525cbcc2------2</link>
            <guid isPermaLink="false">https://medium.com/p/890a1873b325</guid>
            <category><![CDATA[code]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[es6]]></category>
            <dc:creator><![CDATA[Claudia Maniscalchi]]></dc:creator>
            <pubDate>Sun, 02 Dec 2018 22:47:16 GMT</pubDate>
            <atom:updated>2018-12-02T23:03:46.175Z</atom:updated>
            <content:encoded><![CDATA[<p>My roommate is moving out, my usually super-organized apartment is a complete wreck, and I’ve got home reorganizing on the brain. We divided up all of our kitchen implements yesterday, leaving me with a bizarre assortment of items and a long list of things to purchase. It’s as good a scenario as any for helping me to better understand the built-in JavaScript method reduce! Who needs three pour-over coffee makers, after all?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F27Ju5pmIEgv04%2Ftwitter%2Fiframe&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2F27Ju5pmIEgv04&amp;image=https%3A%2F%2Fmedia.giphy.com%2Fmedia%2F27Ju5pmIEgv04%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="315" frameborder="0" scrolling="no"><a href="https://medium.com/media/1265545c04399e5f53e6e1723ae429fb/href">https://medium.com/media/1265545c04399e5f53e6e1723ae429fb/href</a></iframe><p>In learning Javascript I often found reduce to be far less intuitive than other JS methods like map, filter, or includes. Mostly, this is because of the presence of the accumulator argument, and the fact that this function makes several passes before returning a final reduced result. In reality the function is a highly-streamlined way to carry out an involved process, and I’ll be going through it step by step here.</p><p>The official ECMAScript® documentation walks through the steps of Array.prototype.reduce as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b_qu7YN3Zdz3wJuFxIrYpQ.png" /><figcaption>source: <a href="https://tc39.github.io/ecma262/#sec-array.prototype.reduce">https://tc39.github.io/ecma262/#sec-array.prototype.reduce</a></figcaption></figure><h4>…let’s simplify that.</h4><p>Reduce takes two arguments:</p><ol><li>An arrow function</li><li>An initial argument</li></ol><pre>ex: array.reduce(() =&gt; {}, &#39;&#39;)</pre><p>In this example, I’m reducing an array down to a string, given that the second, initial argument is an empty string. The second argument could be any number of things, though, be it an array, an object, a variable which points to another object, etc.</p><p>Here’s what I’ve got in my kitchen:</p><pre>let duplicates = [&#39;pepper mill&#39;, &#39;silicone spatula&#39;, &#39;silicone spatula&#39;, &#39;pour-over coffee maker&#39;, &#39;growler&#39;, &#39;two-cup measure&#39;, &#39;pepper mill&#39;, &#39;pour-over coffee maker&#39;, &#39;pour-over coffee maker&#39;, &#39;two-cup measure&#39;, &#39;growler&#39;, &#39;silicone spatula&#39;]</pre><p>Given my duplicates array, I’d like to return an object which displays the count for each duplicate item, so the bare structure I’m starting with looks like this (note the second argument is an empty oject):</p><pre>const organizedKitchen = duplicates.reduce(() =&gt; {}, {})</pre><p>The arrow function takes two arguments, itself:</p><ol><li>The accumulator</li><li>An array element</li></ol><p>Essentially, when reduce runs we’re passing our second argument of {} into the arrow function; it becomes our accumulator. The arrow function runs one time for every element in the array, and for each run the return result is passed <em>back</em> into the arrow function as the first argument. The starting empty object is altered on each pass, until there are no more elements in our array to reduce. Passing in the arguments I discussed looks like this:</p><pre>const organizedKitchen = duplicates.reduce(<br>  (acc, item) =&gt; {&lt;work some magic here&gt;}, {}<br>)</pre><p>I now want to assign a key-value pair to my accumulator for every element in my array; the keys will be the items’ names, the values thir counts. I’ll use the pattern acc[item] = acc[item] + 1 || 1. In other words, acc[item] assigns the item to my object, and its value is set either to 1, if it’s not already present in the object, or I’m incrementing its count.</p><p>The final product is as follows — be sure to return your accumulator inside the arrow function!</p><pre>const organizedKitchen = duplicates.reduce(<br>  (acc, item) =&gt; {<br>    acc[item] = acc[item] + 1 || 1<br>    return acc<br>  }, {}<br>)</pre><p>Now if I drop console.log(acc) immediately above the return statement, our initial {} evaluates as below on each consecutive pass. And that’s it!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2JxQiHp3UPeuPrNw8BVm5A.png" /></figure><p>To give one more example of how reduce works, I’m going to condense my shopping list array into a string, with some nice formatting. (Note: this process could be more easily accomplished using join, this is for illustrative purposes.)</p><pre>let shoppingList = [&#39;mixing bowls&#39;, &#39;coffee grinder&#39;, &#39;whisk&#39;, &#39;salad spinner&#39;, &#39;box grater&#39;]</pre><p>To reduce this list into a string, I’ll pass a string as my second argument, which is then passed into my arrow function:</p><pre>const simplifiedList = shoppingList.reduce(<br>  (acc, item) =&gt; {&lt;more magic here&gt;}, &#39;To buy: &#39;<br>)</pre><p>I’m going to use a little logic to turn out a formatted string in one go, the final code for which looks like:</p><pre>let shoppingList = [&#39;mixing bowls&#39;, &#39;coffee grinder&#39;, &#39;whisk&#39;, &#39;salad spinner&#39;, &#39;box grater&#39;]</pre><pre>const simplifiedList = shoppingList.reduce(<br>  (acc, item) =&gt; {<br>    if (shoppingList.indexOf(item) &lt; shoppingList.length - 1) {<br>      return acc + item + &#39;, &#39;<br>    } else {<br>      return acc + &quot;and &quot; + item<br>    }<br>    return acc<br>  }, &#39;To buy: &#39;<br>)</pre><p>If I evaluate this function with a console.log(acc), you can see each item being added onto the end of my string:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AKU0mj19ErD7X61Z0MQ2DA.png" /></figure><p>I hope this explanation will come in handy for anyone reading this, walking through the function step by step has definitely been an excellent learning exercise for me. Now I can use reduce to my heart’s content, but I should probably get to organizing this kitchen, first. Until next time!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=890a1873b325" width="1" height="1" alt=""><hr><p><a href="https://medium.com/truthy-or-falsy/reduce-ing-clutter-with-javascript-890a1873b325">Reduce-ing Clutter with JavaScript</a> was originally published in <a href="https://medium.com/truthy-or-falsy">Truthy or Falsy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Project Mode with React, Redux and Rails]]></title>
            <link>https://medium.com/truthy-or-falsy/project-mode-with-react-redux-and-rails-5a219d1282d9?source=rss-ff8525cbcc2------2</link>
            <guid isPermaLink="false">https://medium.com/p/5a219d1282d9</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[redux]]></category>
            <category><![CDATA[rails]]></category>
            <category><![CDATA[react]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Claudia Maniscalchi]]></dc:creator>
            <pubDate>Wed, 19 Sep 2018 15:49:47 GMT</pubDate>
            <atom:updated>2018-09-19T16:56:06.837Z</atom:updated>
            <content:encoded><![CDATA[<p>I’ve just started my final of five modules as a student at Flatiron School, which means I’m in project mode from here on out. I have three weeks to build something all my very own, using the multitude of skills I’ve learned up to this point. Three weeks may seem like a lot of time, but in reality, it’s a heavy lift for someone who’s never done this before. That’s not to say that I’m not <em>super psyched</em> to build something I’m passionate about, I really am, heavy lift or no.</p><p>As this post’s title gives away, I already know which languages and frameworks I’m going to be using for this project. That’s a first step, sure, but there is so much more to plan out, between deciding on my React components and their hierarchies, wireframing my app, figuring out my relational models, deciding on any libraries I want to integrate for added functionality… I’ll freely admit to being right in the middle of this planning process, so what I’m going to present here is sort of my initial thought process in action: I came up with a general idea, I found an API I want to work with, and I wanted to prove to myself that I could proceed with this concept before getting too deep into the planning stages.</p><p>So, in a day, I built a quick-and-dirty React front-end with a Rails back-end, utilizing Redux for my state management and the <a href="https://www.goodreads.com/api/index">Goodreads API</a>. My goal was to be able to search in my app for a book title, query Goodreads for matches, and render those book matches on the page. At the end of the day I was able to:</p><ol><li>Execute a search in React</li><li>Send a POST request to Rails from my front-end</li><li>Make an API call from Rails, incorporating my search term</li><li>Receive xml back from the API</li><li>Convert that xml to JSON</li><li>Send that object back to my front-end</li><li>And finally, use that returned object from my API call to update my state</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*xt6iNMPMfo6rchrVD_-QPw.gif" /></figure><p>That was the extent of the functionality I was going for. As I mentioned, this was more a dry run than anything, a test I gave myself before diving into a larger-scale project. Plus, it was some great Redux practice! (A quick aside: I have to give significant credit to <a href="https://medium.com/u/d058882d8cd2">Stephen Grider</a>’s Udemy course <a href="https://www.udemy.com/react-redux/learn/v4/"><strong>Modern React with Redux</strong></a>. I leaned heavily on his methods, as this was my first time integrating Redux into a React project of my own, and I heartily recommend this course to anyone who wants to bolster their beginner (or even non-existant) React &amp; Redux skills.)</p><h4>The Steps I Took (in Broad-ish Strokes)</h4><p>I’m going to glance over the React and Rails boilerplate setup here and jump right into the meat of it. The first real step I took was building out a SearchBar controlled component for my front-end. You can see that the search term (I called it input) lives in local state, since that data isn’t pertinent to the greater app’s state.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*emPuYTNF2xSFwqlpx2nN5A.png" /></figure><p>I have two functions to handle the input: handleInputChange, which hooks up the controlled form, and handleFormSubmit, where I pass the user input to my bookSearch action controller, and then set the input back to an empty string after submit. I’m have access to the bookSearch action controller thanks to mapDispatchToProps; the bottom three things I’m importing are all for this purpose: connect, bindActionCreators, and the bookSearch function.</p><p>According to the Redux documentation, bindActionCreators:</p><blockquote>Turns an object whose values are <a href="https://redux.js.org/glossary#action-creator">action creators</a>, into an object with the same keys, but with every action creator wrapped into a <a href="https://redux.js.org/api/store#dispatch">dispatch</a> call so they may be invoked directly.</blockquote><blockquote>[…] The only use case for bindActionCreators is when you want to pass some action creators down to a component that isn&#39;t aware of Redux, and you don&#39;t want to pass <a href="https://redux.js.org/api/store#dispatch">dispatch</a> or the Redux store to it.</blockquote><p>I’m calling on bindActionCreators in mapDispatchToProps so that I’m able to invoke bookSearch directly when a user submits a search, and I’m using connect to make sure my component has access to the bookSearch function as props.</p><p>Long story short, when a user submits their search, they’re calling this action creator:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8CbosYeBSasJuxvHEQY3vQ.png" /></figure><p>This is where things get a little involved, since I’m executing a fetch request with a POST method to Rails, which for my purposes lives on localhost:3001. I’ve created a custom route at book_search, which exists for the sole purpose of this post request.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KkIeq_Zmgi_RWVwRLHrSAQ.png" /></figure><p>Rails receives this post as params via the book_search action in my BooksController. I incorporate that input into an an API request, and send it off like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q-oTbBjPtbow2SIBHhDcsA.png" /></figure><p>The RestClient method I’m using comes from the <a href="https://github.com/rest-client/rest-client">REST client gem</a>, which elegantly handles restful HTTP requests. It fires off the request and in return I get a nice clean xml response saved to my request variable (the xml response is a function of the Goodreads API call, which doesn’t return JSON). To convert the response to a JSON-like object I use Ruby’s built-in <a href="https://www.rubydoc.info/docs/rails/4.0.0/Hash.from_xml">Hash.from_xml</a> method. Then I pass that formatted response back to my front-end using render json: response.</p><p>Referring back to my action controller, the object I’m returning has a type of SEARCH_BOOKS, with a payload of a <em>promise</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*NHdrF_6Q2RoLlI4SjK3urQ.png" /></figure><p>Uh-oh. Again, I have to give thanks to Stephen Grider, who solves this problem in his code-along class using <a href="https://www.npmjs.com/package/redux-promise">Redux Promise</a> as middleware. I create my store in my project’s injex.js using ReduxPromise, so all of my reducers have access to this package’s functionality.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u0TAiU-KSTqS0Vp49sW6GA.png" /></figure><p>To bring it all together, when a user submits a search for a book, they’re hitting my action controller, getting an object with the type of SEARCH_BOOKS, and the object that action controller makes (remember, the payload is still a promise at this point) is sent automatically to my reducers. The reducer sees that promise, and Redux Promise converts that to a JavaScript object, which can then be used to update my app’s state. Here’s the reducer which handles this action:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LTZrcvjpdLbSFWwKAQPAXw.png" /></figure><p>My app’s default state is a simple empty array (line 3), and this long string of action.payload.GoodReadsResponse.search.results.work is how I need filter the JSON response from Goodreads to get at the specific data I need for my app, namely, the actual book search details. Here’s what the unadulturated Goodreads response looks like, after it’s been converted by Redux Promise:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/586/1*cdwjDNXAPob7SqzbIYy8Tw.png" /></figure><p>I then created a new component called BookSearchList, which is where I&#39;m doing the actual updating of state. I have access to the bookSearchResults object, because I’ve defined it in my rootReducer:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iXyjNSF2ytL8B25YP7jsaQ.png" /></figure><p>Now I can use mapStateToProps to set those results as my props, which I then connect to my BookSearchList.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XoLAtMTXImSFsiIzEH_GSQ.png" /></figure><p>My component now has access to the search results via this.props, and I can map over that array to create a Book component for each book the search returns. The final product is here:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/1*KEAdmJiBpW0ONTph1ebguQ.png" /></figure><p>That’s it! I’ve since done a significant amount of planning, and I’ve completely revamped my back-end. My next step, now that I have a clear idea of the steps I need to take to build my project, is to set up my React front-end over from scratch, and work in implementing auth. I don’t mind, though, because this exercise was a great learning experience for me, and just as importantly, I gained the conviction that I can totally do this, and it’s going to be a whole lot of fun.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5a219d1282d9" width="1" height="1" alt=""><hr><p><a href="https://medium.com/truthy-or-falsy/project-mode-with-react-redux-and-rails-5a219d1282d9">Project Mode with React, Redux and Rails</a> was originally published in <a href="https://medium.com/truthy-or-falsy">Truthy or Falsy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chrome DevTools Has It All (…And Then Some)]]></title>
            <link>https://medium.com/truthy-or-falsy/chrome-devtools-has-it-all-and-then-some-4ea68f33185a?source=rss-ff8525cbcc2------2</link>
            <guid isPermaLink="false">https://medium.com/p/4ea68f33185a</guid>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Claudia Maniscalchi]]></dc:creator>
            <pubDate>Wed, 22 Aug 2018 17:00:01 GMT</pubDate>
            <atom:updated>2018-08-22T17:00:01.064Z</atom:updated>
            <content:encoded><![CDATA[<p>Before my life as a developer, I’d use Chrome DevTools often to poke around websites, but mostly out of curiosity. I’d look at all of the assets on a page under the Sources tab, I’d mess around with the CSS, select elements to inspect with the handy arrow tool in the top left… All of this is to say: I was vaguely aware of the power of this tool, and blissfully ignorant of its more involved uses.</p><p>My relationship with DevTools has changed significantly in recent months, though, having enrolled in a coding bootcamp. And consequently, a few things in particular have become really obvious: DevTools not exactly the most intuitive piece of software to use, and I’ve <em>most definitely</em> been using it inefficiently. For something I need to use all the time — every single day, really — I’d clearly benefit from using it right. Making good use of the functionality Google has kindly provided me and the rest of the world will, without question, make my life easier.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P8Uems3GmHssdlA8ikEXEg.png" /></figure><h3>Welcome to the Jungle</h3><p>You see that? Craziness. Granted, a lot of this functionality is intended for advanced users, so the important thing is to not be freaked out, and find the uses which will help you accomplish what you need to. Explore the interwebs, there are a multitude of blogs out there on this very subject, you’re bound to find something which will change your workflow.</p><p>Hence, this post. I’ve scoured a number of resources on Chrome’s DevTools, and in an effort to better learn how to use it myself, I’ve compiled a few tips which stuck out to me as especially useful. Hopefully, if you’re a beginner like me, this post will likewise be of some use!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*KJQ9n3bDb1ewylGD9SxhKg.gif" /></figure><h3>Customize That Console</h3><p>I’m in the thick of learning Javascript and specifically DOM manipulation, so the console is my new best friend. Until today, I didn’t look too hard at these customizations available to me, but I should have because (surprise!) I’ve realized they can be super helpful.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*o1iz6N5Ygqqn-rjwKbEMMw.png" /></figure><p>Here I’ve selected three options by clicking on that blue gear icon, and they do the following:</p><ol><li>Preserve Log: Persists the data in my console when I refresh the page (which I seem to be doing constantly). This is going to cut down on a lot of re-entering of inputs.</li><li>Log XMLHttpRequests: Here you can see I loaded a project I’m working on, and the fetch requests I made are shown below, along with the HTTP verbs and the API resources requested. I find this visualization really useful.</li><li>Autocomplete from history: This functionality I believe is a default, and with good reason — being able to call up inputs you’ve previously made can be handy. If you find that annoying, though, you can turn it off, as well as clear your console’s history.</li></ol><h3>Recalling &amp; $electing Elements</h3><p>Similar to jQuery, the dollar sign in Chrome’s Developer Tools is used for a number of handy input shorcuts.</p><h4>0, 1, 2, 3…</h4><p>$0 is all it takes, in combination with the select elements pointer tool, to display elements on your page in the console, and from there manipulate them. Below you can see two inputs: first <strong>$0</strong> on its own, which displays the div I’m hovering over on left as a DOM object, and below that <strong>console.dir($0)</strong>, showing that same element’s corresponding JavaScript object.</p><p>Additionally, <strong>$1</strong> will call up the previously selected DOM element, <strong>$2</strong> the one selected before that, and so on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-axaJxhqyUf5LsIhMKhTlg.png" /></figure><h4>$(“selector”) and $$(“selector”)</h4><p>These two inputs are shorthand for JavaScript’s <strong>document.querySelector(“selector”)</strong> and <strong>document.querySelectorAll(“selector”)</strong> functions, returning the first element of a specified type, and all elements of that type, respectively.</p><p>I tested it out in my console, using a class of “note-titles,” as an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_HBTiT5F0htpxs_5C0hTPA.png" /></figure><h4>Underscore It!</h4><p>You can retrieve the value of the previous result in your console by inputting <strong>$_</strong> , exactly how the underscore retreives the previous result in your Ruby Pry or IRB session. This proves invaluable in seeing the results of functions or calculations as you chain them together, step by step.</p><h3>contentEditable = true</h3><p>Here’s a really cool one. If you type <strong>document.body.contentEditable=true</strong> into your console, you gain the ability to dynamically edit any text on the current document, delete or copy &amp; paste entire html elements, rearrange your page’s layout. Most everything in the DOM can be manipulated this way!</p><p>I messed around with my app here, deleting a picture, editing some headers, labels, and buttons, moving the Add A Note below the note display… this example is silly, but my point is that it took all of 30 seconds to make these edits.</p><p>Setting the document’s contents to Editable is a super powerful shortcut for previewing changes before you make them in the document, or for creating mockups.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qZWpLmwDp0e-pwJfpaS21w.png" /></figure><h3>Setting Breakpoints</h3><p>Debugger is a fantastic tool, it triggers your code to stop running at a specific breakpoint and allows you to inspect your code at that specific state in the Sources tab. You probably already know that one, though. What I didn’t knoew before I started researching, is that you can set all sorts of breakpoints in Chrome which get triggered at any number of events. Check it out:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*r1msJUYwk7ewfQ-2K44C-A.png" /></figure><p>One way to set breakpoints on a specific element is to select it in the Elements tab, right click, select <strong>Break on</strong>, and then choose the type of events you want to trigger the break. If you want to trigger breakpoints for, say, node removals across all elements, simply select higher up in the tree on body.</p><p>An even easier way to check out all breakpoints is to navigate to Sources. Here you can see I selected a breakpoint on the sidebar (above), that’s showing up with a checkbox, but I can also add in any other kind of breakpoint needed, say, for when I’m executing fetch requests to my database. Just click on the plus button, and choose Any request, or specify the one you want:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/826/1*OWdtcpQQFkFS0r3pAWAZ4w.png" /></figure><p>That’s all I’ve got! Thanks for reading, hopefully these tips shed some light on and help demystify Chrome’s DevTools. My advice is, don’t stress it if you feel like you don’t know how to use it well, since it can look especially overwhelming. Bearning how to use it, like anything, is a process, it takes practice, and you’ll get there, bit by bit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*CjLjUbDOHcWphDQ9xxugAg.gif" /></figure><p>Resources:</p><ul><li><a href="http://anti-code.com/devtools-cheatsheet/">Chrome Devtools Cheatsheet</a></li><li><a href="https://flaviocopes.com/chrome-devtools-tips/">A list of cool Chrome DevTools Tips and Tricks</a></li><li><a href="https://medium.com/@cihadturhan/20-questions-to-learn-chrome-developer-tools-basic-level-d16d7dcd108c">20+ Questions to learn Chrome Developer Tools — Basic Level</a></li><li><a href="https://hackernoon.com/twelve-fancy-chrome-devtools-tips-dc1e39d10d9d">Twelve Fancy Chrome DevTools Tips</a></li><li><a href="https://medium.freecodecamp.org/10-tips-to-maximize-your-javascript-debugging-experience-b69a75859329">Things you probably didn’t know you could do with Chrome’s Developer Console</a></li><li><a href="https://medium.freecodecamp.org/mastering-chrome-developer-tools-next-level-front-end-development-techniques-3ac0b6fe8a3">Mastering Chrome Developer Tools: Next Level Front-End Development Techniques</a></li><li><a href="https://tutorialzine.com/2015/03/15-must-know-chrome-devtools-tips-tricks">15 Must-Know Chrome DevTools Tips and Tricks</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4ea68f33185a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/truthy-or-falsy/chrome-devtools-has-it-all-and-then-some-4ea68f33185a">Chrome DevTools Has It All (…And Then Some)</a> was originally published in <a href="https://medium.com/truthy-or-falsy">Truthy or Falsy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Regexp with Steinbeck & Salinger]]></title>
            <link>https://medium.com/truthy-or-falsy/regexp-with-steinbeck-salinger-764cfe0fb656?source=rss-ff8525cbcc2------2</link>
            <guid isPermaLink="false">https://medium.com/p/764cfe0fb656</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[regular-expressions]]></category>
            <category><![CDATA[regex]]></category>
            <category><![CDATA[ruby]]></category>
            <dc:creator><![CDATA[Claudia Maniscalchi]]></dc:creator>
            <pubDate>Thu, 26 Jul 2018 03:06:50 GMT</pubDate>
            <atom:updated>2018-07-26T16:02:47.893Z</atom:updated>
            <content:encoded><![CDATA[<p>Since I began learning Ruby, I’ve come across many, many Regular Expressions, or Regex/Regexp, and I’ll admit, for a while I had no idea what I was looking at. They were totally mystifying. I’d see one used in a solution on StackOverflow or CodeWars, or thrown into a Learn.co lab, and I’d mostly just take the author’s word for it that that jumble of letters, numbers, and characters would work as described. I had bigger fish to fry, basic Ruby functionality to learn. I’ve come to realize, though, that when appropriate, regular expressions can be essential for DRY code. They’ll make your life so much easier, and it’ll feel like magic at work.</p><h4>R/regE/ex(p) — What it it?</h4><p>Regex is not specific to Ruby, it’s actually used in a large number of programming languages. Essentially, it’s a pattern matching tool — and a really powerful one. In Ruby when we use a regex, we’re passing an expression to a code library called <a href="https://github.com/k-takata/Onigmo">Onigmo</a>, which then evaluates the expression for us. With this amazing built-in functionality, we can check for the presence of numbers, letters, characters, words, specific patterns of characters, it goes on and on, and some real-world uses I’ve come across range from email address validations to scraping large bodies of text.</p><p>Rather than going in-depth into the particulars of regex functionality, I’ve put together some specific examples which highlight the versatility of these expressions. For the first, I look to Melville to show regex in action:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*6ILBXjRJvTAbRayuNUJLeg.png" /></figure><p>Woah. How did that just happen? I’ve just chopped off the last five characters of this string by evaluating regex with a gsub method, and I’ve plugged a new period onto the end of the sentence. Let’s break this down:</p><p>Regex statements are most commonly contained within forward slashes /.../ or curly braces %r{...}, or alternatively, can be created with Regexp.new. Looking within the slashes, as in my above example, the period symbol represents one single character, the {5} tells Ruby I want to check for five of those single characters (any characters at all!), and the $ anchor specifies that I want to evaluate moving backwards from the end of the string. Gsub made that match, and swapped the last five characters with a single period. Nice to meet you, Ish.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/340/1*v5fLEHFURY8Bt-9Oz0NtZg.gif" /></figure><p>I mentioned being mystified by regex, and it was this sort of expression that had me raising my eyebrows: <strong>/[^A-Za-z0–9_]/</strong></p><p>I can thell there’s a lot going on here, clearly something having to do with numbers and letters, but there are also a whole lot of non-alphanumeric characters thrown in. It turns out this expression is actually filtering for non-word characters, and the expression within the slashes — <strong>[^A-Za-z0–9_] </strong>— is what’s called a <em>character class</em> within Ruby. A character class is designated by square brackets, and represents an expression which searches for any instance of these characters <em>in any order</em>. Without these brackets, we’d be searching for this exact pattern, starting at the beginning of the line (as indicated by the carat ^ anchor). This literal phrase, of course, is nonsensical: <strong>A-Za-z0–9_</strong>.</p><p>Inside the character class, however, the carat indicates that you’re looking for all characters which are <em>not</em> present in the set, and we’re able to look at ranges of data. The A-Z and a-z are shorthand for alphabetical ranges, both capitalized and not, and the 0–9 captures all numeric characters.</p><p>This <strong>/[^A-Za-z0–9_] </strong>/ phrase is a lot to remember, and so Ruby has some handy metacharacters representing special character classes like this one. They can be called on by a backwards (escape) slash followed by a specific character. This one is \W!</p><p>Here you can see a nice comparison of six different character classes /metacharacters at work, though this time I’m analyzing the first sentence of <em>The Grapes of Wrath</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/675/1*RUcTedh0ArO9yYHPUvyQ5A.png" /><figcaption>example generated on <a href="https://www.regextester.com/">https://www.regextester.com/</a></figcaption></figure><p>From top to bottom the examples represent these six regular expressions:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-avCafLVPkNChn_r8DRvpQ.png" /><figcaption>screenshot from <a href="https://bneijt.nl/pr/ruby-regular-expressions/">https://bneijt.nl/pr/ruby-regular-expressions/</a></figcaption></figure><p>Pretty amazing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/465/1*sD968sw3eorH_en4DFwtBA.gif" /></figure><p>Finally, I’d like to put together a few regex to catch this punctuation weirdness from J.D. Salinger’s <em>Raise High the Roof Beam, Carpenters and Seymour: An Introduction:</em></p><h3>I privately say to you, old friend… please accept from me this unpretentious bouquet of early-blooming parentheses: (((()))).</h3><p>Okay, four sets of nested parentheses?! How could I check if my text has any bouquets like this? I could analyze for this using any of these regex (whether I’d want to use #s 1 or 3 is another matter):</p><p><strong>/\(\(\(\(\)\)\)\)/</strong></p><p><strong>/\({4}\){4}/</strong></p><p><strong>/[[:punct:]][[:punct:]][[:punct:]][[:punct:]][[:punct:]][[:punct:]][[:punct:]][[:punct:]]/</strong></p><p><strong>/[[:punct:]]{8}/</strong></p><p>The first checks for the exact series of parentheses, each separated by a backslash because they’re special caracters. The second makes use of {n} repetition for each of the four open- and closed-parentheses. The third finds a series of eight consecutive punctuation marks (yikes!), and the fourth cleans that up nicely with {8}. The last two are not an exact match, but I’ll take those odds. How often do you see eight punctuation marks in sequence?</p><p>Regex is stunningly versatile, and the pattern matching combinations are endless. It’s good to learn any by heart which you find yourself going back to over and over again, otherwise I say just pop over to the Ruby documentation for special cases. Regex is your friend, go and check it out!</p><p>Sources:</p><p><a href="https://ruby-doc.org/core-2.5.1/Regexp.html#method-i-match">https://ruby-doc.org/core-2.5.1/Regexp.html</a>, <a href="https://www.youtube.com/watch?v=gCY8ZWi7RKs">https://www.youtube.com/watch?v=gCY8ZWi7RKs</a>, <a href="https://www.youtube.com/watch?v=q70q-QyIios">https://www.youtube.com/watch?v=q70q-QyIios</a>, <a href="https://bneijt.nl/pr/ruby-regular-expressions/">https://bneijt.nl/pr/ruby-regular-expressions/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=764cfe0fb656" width="1" height="1" alt=""><hr><p><a href="https://medium.com/truthy-or-falsy/regexp-with-steinbeck-salinger-764cfe0fb656">Regexp with Steinbeck &amp; Salinger</a> was originally published in <a href="https://medium.com/truthy-or-falsy">Truthy or Falsy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pry, Pry, and Pry Again]]></title>
            <link>https://medium.com/truthy-or-falsy/pry-pry-and-pry-again-62f3f774c4b8?source=rss-ff8525cbcc2------2</link>
            <guid isPermaLink="false">https://medium.com/p/62f3f774c4b8</guid>
            <category><![CDATA[rubygems]]></category>
            <category><![CDATA[ruby]]></category>
            <category><![CDATA[codingbootcamp]]></category>
            <category><![CDATA[coding]]></category>
            <dc:creator><![CDATA[Claudia Maniscalchi]]></dc:creator>
            <pubDate>Thu, 05 Jul 2018 03:51:45 GMT</pubDate>
            <atom:updated>2018-07-05T04:04:26.684Z</atom:updated>
            <content:encoded><![CDATA[<p>I am new to programming. Like, brand spanking new. My educational background is in music and literature, and for the past 10 years I worked within the world of public media. That’s why diving into the nitty-gritty of Ruby in the first few weeks here at Flatiron School has been a humbling experience, to say the least.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*cAnOzTLjMxptbfLvo5HmAQ.gif" /></figure><p>I find myself having to adjust to new ways of thinking in order to meet the demands of my coursework — work which would have been more or less meaningless to me just a few months ago. The learning curve can be a steep one, and I find myself actively cultivating new habits and adopting new tools to make my daily learning really take root. One of those tools which has especially helped me to adapt is <a href="http://pryrepl.org/">Pry</a>.</p><h4>What’s Pry, and why should I care?</h4><p>Pry is a <strong>REPL</strong> gem, or Read–Eval–Print Loop, created by <a href="https://github.com/banister">John Mair</a>, <a href="https://github.com/conradirwin">Conrad Irwin</a>, and <a href="https://github.com/rf-">Ryan Fitzgerald</a>, with the aid of the greater Github community. If the concept is new to you, a REPL:</p><p>Reads (or accepts) a user input, and stores it in your computer’s memory</p><p>Evaluates your input , meaning it processes whatever data you’ve inputted</p><p>Prints the evaluated result</p><p>Loops, then exits out of the process — the above R, E &amp; P represent one loop</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*_R918wE5TCBH_3ivI81wmw.png" /></figure><p>In short, a REPL lets you test out and explore your code in a private, interactive environment. Use it to see if that method you just built elvaluates as true or false, to see how many elements exist in an array, to dissect some really complicated nested hashes, or even just to do some simple math.</p><p>There are <a href="http://joel.franusic.com/Online-REPs-and-REPLs/">many web-based REPLs</a> available, but for my purposes I’m working in my terminal, and without Pry I’d be dependent on IRB to test my code. IRB is Ruby’s built-in REPL, it’s short for Interactive Ruby Shell. That wouldn’t be the worst situation to be in, but as I’ve learned, Pry has a wide range of functionality which IRB doesn’t support, and it can make all the difference in troubleshooting your code.</p><h4>Pry vs IRB</h4><p>When compared side by side, a few major differences between Pry and IRB are readily apparent: Pry supports syntax highlighting, while IRB is completely monotone, and Pry has more uniform indentation formatting. Let’s take a look:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SHMNYV52DYZv50L9lCrL7g.jpeg" /><figcaption>The same code entered in Pry (above) vs. IRB (below)</figcaption></figure><p>These examples are a bit messy, but intentionally so. I’ve found working in your terminal can get messy, unless you’re clearing it all the time. The advantage here to Pry I think is obvious — those strings, hashes, arrays, and return values pop right out in the middle of an otherwise dense chunk of code. It’s also less busy; in IRB that “2.3.3 :001 &gt;<em>”</em> over and over again is not especially beautiful or helpful. Pry simply indicates where you are in your pry session with a [3] for line 3, followed by pry(main), which indicates where you are within the scope of your pry session.</p><h4>Okay, Pry looks nice, but what can it do?</h4><p>In the very short time I’ve been at Flatiron I’ve used <strong>binding.pry</strong> countless times. It’s one of the first applications of Pry we learned, and with good reason. How you use it is simple — in any document you want to run, first make sure you “require ‘pry’” at the top, then drop in a breakpoint with “binding.pry” anywhere you want to inspect within the body of the document. When you run your program, pry will open up at the precise moment you put in your binding, allowing for some really precise, targeted troubleshooting. This is called <strong>Runtime Invocation</strong>.</p><p>Here’s a simplistic example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/802/1*yehvd9qwSPPQpeMuBhJx4g.jpeg" /></figure><p>Because I put my pry in the middle of a block, I’m able to see what |num| represents, in this case a 1, then if I loop through again a 3, and so on. I can test out the program at this point and confirm the return values I’ll be getting: [3, 21, 30].</p><p>One of the most impressive uses of Pry I learned from <a href="https://www.youtube.com/watch?v=3RQFkga_6ok">YouTube</a>, and it’s a game changer: you can <em>go inside self</em>. If I start a pry session with the command “pry” then set a variable <em>lucky_number</em> equal to 17, I can move into the scope of that integer with the basic shell command “cd lucky_number.” From there, if I call <em>self</em> I’ll see a return value of 17. If I input <em>self.class</em>, I’ll get Fixnum. The command prompt “ls” returns a list of methods I can call on myself (i.e. 17). Here’s how this all looks:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VIxmEKiDDpWLhSUQLzPpNA.png" /><figcaption>self.positive? =&gt; true</figcaption></figure><p>This kind of functionality is called State Navigation. As <a href="https://github.com/pry/pry/wiki/State-navigation">Pry’s documentation</a>on Github describes:</p><blockquote>Taking inspiration from the unix command shell, Pry provides commands to make navigating around your program’s runtime state both familiar and natural.</blockquote><p>I just used shell commands “cd” and “ls ”within Pry, and I was able to inspect self and pull up a list of methods. Not only that, but they’re clearly organized into categories. Here we see Comparable, Numeric, Integer, Fixnum, and local methods. If I want to get back outside of this object, I just re-enter “cd” and I’m back at my pry(main) input.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*h-xbpeckyNv5l0pA7bfBDA.gif" /></figure><p>It doesn’t stop there. By using a period, I can actually navigate and execute tasks within my computer’s command line without ever having to exit pry. Here you can see I looked at the files in my current directory with “.ls”, changed directories with “.cd Development/blog-posts”, created a new file with “.touch”, and then opened it in Atom, all within my Pry session.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*srZLuFQdLOhUg0rMo86lHQ.png" /></figure><p>The Pry documentation is extensive, just like the functionality. I’ve only brushed the surface here, and I expect Pry will only grow more and more useful to me as a tool the longer I use it. I know that even as a beginner, Pry is a life saver, so I can only imagine the benefits that’ll come with time and loads of practice. I look forward to prying and learning for many years to come!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62f3f774c4b8" width="1" height="1" alt=""><hr><p><a href="https://medium.com/truthy-or-falsy/pry-pry-and-pry-again-62f3f774c4b8">Pry, Pry, and Pry Again</a> was originally published in <a href="https://medium.com/truthy-or-falsy">Truthy or Falsy</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>