<?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: vamsi pavan mahesh gunturu</title>
    <description>The latest articles on DEV Community by vamsi pavan mahesh gunturu (@gvpmahesh).</description>
    <link>https://dev.to/gvpmahesh</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%2F49039%2F08387a80-4738-4bca-90ad-e87f58182aa2.jpeg</url>
      <title>DEV Community: vamsi pavan mahesh gunturu</title>
      <link>https://dev.to/gvpmahesh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gvpmahesh"/>
    <language>en</language>
    <item>
      <title>Review on doing TDD for 14 days, 100% test coverage 😱</title>
      <dc:creator>vamsi pavan mahesh gunturu</dc:creator>
      <pubDate>Sat, 17 Apr 2021 04:02:33 +0000</pubDate>
      <link>https://dev.to/gvpmahesh/review-on-doing-tdd-for-14-days-100-test-coverage-427</link>
      <guid>https://dev.to/gvpmahesh/review-on-doing-tdd-for-14-days-100-test-coverage-427</guid>
      <description>&lt;p&gt;We have started doing TDD by pair programming at work for the past 14 days. &lt;/p&gt;

&lt;p&gt;Some of the benefits that we could observe :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Tests don't feel like extra work that we need to fill once the code is written, they are part of the workflow.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Insane clarity on how the interfaces are going to look like because we design the interfaces in tests themselves.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Doing TDD is fun, you get a small joy whenever the test changes from red to green.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The side effect of all this is 100% test coverage.&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="no"&gt;Finished&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="mf"&gt;3.17&lt;/span&gt; &lt;span class="n"&gt;seconds&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;files&lt;/span&gt; &lt;span class="n"&gt;took&lt;/span&gt; &lt;span class="mf"&gt;6.89&lt;/span&gt; &lt;span class="n"&gt;seconds&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="nb"&gt;load&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="mi"&gt;102&lt;/span&gt; &lt;span class="n"&gt;examples&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt; &lt;span class="n"&gt;failures&lt;/span&gt;

&lt;span class="no"&gt;Coverage&lt;/span&gt; &lt;span class="n"&gt;report&lt;/span&gt; &lt;span class="n"&gt;generated&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="no"&gt;RSpec&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="sr"&gt;/Users/use&lt;/span&gt;&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;work&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;video_ops_backend&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;app&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;coverage&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt; &lt;span class="mi"&gt;813&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="mi"&gt;814&lt;/span&gt; &lt;span class="no"&gt;LOC&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mf"&gt;99.88&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;covered&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Okay maybe I lied a little, we have not covered one line :p &lt;/p&gt;

&lt;p&gt;That line happens to be in our exceptions handler, where we are not covering Generic catching of exception because we are catching all of them in the hierarchy above.&lt;/p&gt;

&lt;p&gt;I don't think we are ever going back to writing code and backfilling tests after discovering this wonderful world of TDD.&lt;/p&gt;

&lt;p&gt;Full disclosure:&lt;br&gt;
The pair working on this project has a senior engineer(me) and a lead engineer, who are already familiar with the tech stack, writing tests for a couple of years, YMMV.&lt;/p&gt;

</description>
      <category>tdd</category>
      <category>ruby</category>
      <category>rails</category>
      <category>rspec</category>
    </item>
    <item>
      <title>Disable your trackpad for better ergonomics</title>
      <dc:creator>vamsi pavan mahesh gunturu</dc:creator>
      <pubDate>Fri, 21 Aug 2020 06:49:18 +0000</pubDate>
      <link>https://dev.to/gvpmahesh/disable-your-trackpad-for-better-ergonomics-1obb</link>
      <guid>https://dev.to/gvpmahesh/disable-your-trackpad-for-better-ergonomics-1obb</guid>
      <description>&lt;p&gt;TLDR: &lt;em&gt;Disabling the trackpad and getting an external mouse is the least effort thing that you can do to improve your ergonomics.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;I have recently switched to a 13-inch Macbook Pro from the 2014 model 15.6 MBP.&lt;/p&gt;

&lt;p&gt;If you may have noticed, the trackpad area is huge in this machine, which lead to an unnatural posture for me when typing.&lt;/p&gt;

&lt;p&gt;It's been a month I have been using this machine and I started developing ulnar pain between my pinky and wrist. I googled about this, and just to add to my anxiety, the results that came were related to carpal tunnel syndrome.&lt;/p&gt;

&lt;p&gt;I was in disbelief, how can this happen in under a month? I asked in a popular slack channel where devs hang out, regarding this. At least 5 people suggested that it might be due to unnatural posture. And suggested me to get an external keyboard, mouse, and monitor. And I do have to those things with me, but just in a different city, as I moved over to my parent's place at the beginning of this pandemic with just my laptop.&lt;/p&gt;

&lt;p&gt;While I made some arrangements to have that stuff sent back to me, I got a temporary mouse meanwhile. And disabled the trackpad on the laptop so that I need not worry about touching the trackpad.&lt;/p&gt;

&lt;p&gt;I took a day off, and have been using this setup for 2 days. My pain is gone. I just wanted to share this because some of you who are reading this, might have experienced this. Disabling the trackpad and getting an external mouse is the least effort thing that you can do to improve your ergonomics.&lt;/p&gt;

</description>
      <category>watercooler</category>
      <category>productivity</category>
      <category>workstations</category>
    </item>
    <item>
      <title>How redirect_to works in Rails?</title>
      <dc:creator>vamsi pavan mahesh gunturu</dc:creator>
      <pubDate>Thu, 07 May 2020 14:37:57 +0000</pubDate>
      <link>https://dev.to/gvpmahesh/how-redirectto-works-in-rails-1cp9</link>
      <guid>https://dev.to/gvpmahesh/how-redirectto-works-in-rails-1cp9</guid>
      <description>&lt;p&gt;If you are a Rails developer, chances are you have already used &lt;code&gt;redirect_to&lt;/code&gt; bunch of times. But have you ever wondered, how it works?&lt;/p&gt;

&lt;p&gt;Suppose if you put this in your controller code and set the appropriate routing&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;index&lt;/span&gt;
  &lt;span class="n"&gt;redirect_to&lt;/span&gt; &lt;span class="s2"&gt;"https://www.google.com"&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your browser will redirect you to google.com, which is fine. But how does your browser know to redirect to google.com?&lt;/p&gt;

&lt;p&gt;The magic lies here &lt;a href="https://github.com/rails/rails/blob/b738f1930f3c82f51741ef7241c1fee691d7deb2/actionpack/lib/action_controller/metal/redirecting.rb#L58" rel="noopener noreferrer"&gt;https://github.com/rails/rails/blob/b738f1930f3c82f51741ef7241c1fee691d7deb2/actionpack/lib/action_controller/metal/redirecting.rb#L58&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The code is 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="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;redirect_to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{},&lt;/span&gt; &lt;span class="n"&gt;response_options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{})&lt;/span&gt;
      &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="no"&gt;ActionControllerError&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"Cannot redirect to nil!"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;unless&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;
      &lt;span class="k"&gt;raise&lt;/span&gt; &lt;span class="no"&gt;AbstractController&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;DoubleRenderError&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;response_body&lt;/span&gt;

      &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;status&lt;/span&gt;        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_extract_redirect_to_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;response_options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;location&lt;/span&gt;      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;_compute_redirect_to_location&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;options&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="nb"&gt;self&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;response_body&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&amp;lt;html&amp;gt;&amp;lt;body&amp;gt;You are being &amp;lt;a href=&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="si"&gt;#{&lt;/span&gt;&lt;span class="no"&gt;ERB&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Util&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;unwrapped_html_escape&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;location&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;&amp;gt;redirected&amp;lt;/a&amp;gt;.&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;"&lt;/span&gt;
    &lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Basically, the above code is setting the status as 302 by default. And location header to &lt;code&gt;https://www.google.com&lt;/code&gt;. And the response body to&lt;br&gt;
&lt;br&gt;
 &lt;code&gt;You are being &amp;lt;a href="https://www.google.com"&amp;gt;redirected&amp;lt;/a&amp;gt;.&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So when the browser receives a status of 3xx with a location header, it redirects!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the browser, if you see the network, it looks like this&lt;/p&gt;

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

&lt;p&gt;As you can see it's setting the status to 302 &lt;br&gt;
and Location to &lt;code&gt;https://www.google.com&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I was unsuccessful in seeing the response body in the browser, maybe that's just the browser's behavior. Someone can confirm this?&lt;/p&gt;

&lt;p&gt;But I could see response body in &lt;code&gt;curl&lt;/code&gt; request&lt;/p&gt;

&lt;p&gt;It 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="n"&gt;curl&lt;/span&gt; &lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="ss"&gt;:/&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;localhost&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;3000&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="no"&gt;Rebuilt&lt;/span&gt; &lt;span class="no"&gt;URL&lt;/span&gt; &lt;span class="ss"&gt;to: &lt;/span&gt;&lt;span class="n"&gt;http&lt;/span&gt;&lt;span class="ss"&gt;:/&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;localhost&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;
&lt;span class="o"&gt;*&lt;/span&gt;   &lt;span class="no"&gt;Trying&lt;/span&gt; &lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;...&lt;/span&gt;
&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="no"&gt;TCP_NODELAY&lt;/span&gt; &lt;span class="n"&gt;set&lt;/span&gt;
&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="no"&gt;Connected&lt;/span&gt; &lt;span class="n"&gt;to&lt;/span&gt; &lt;span class="n"&gt;localhost&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;port&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="c1"&gt;#0)&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;GET&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt; &lt;span class="no"&gt;HTTP&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;Host&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;localhost&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;3000&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;User&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Agent&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;curl&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="mf"&gt;7.54&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="no"&gt;Accept&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt;&lt;span class="sr"&gt;/*
&amp;gt;
&amp;lt; HTTP/&lt;/span&gt;&lt;span class="mf"&gt;1.1&lt;/span&gt; &lt;span class="mi"&gt;302&lt;/span&gt; &lt;span class="no"&gt;Found&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Frame&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;SAMEORIGIN&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;XSS&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Protection&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;mode&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;block&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Type&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;nosniff&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Download&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;noopen&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Permitted&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Cross&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Domain&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Policies&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;none&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;Referrer&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Policy&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;strict&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;origin&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="k"&gt;when&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;cross&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;origin&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;Location&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;https&lt;/span&gt;&lt;span class="ss"&gt;:/&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;www&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;google&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;com&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;Content&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;text&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;html&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="n"&gt;charset&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;utf&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;Cache&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Control&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;no&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;cache&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Request&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;660668&lt;/span&gt;&lt;span class="n"&gt;ae&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;1176&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mi"&gt;4770&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="mf"&gt;8e82&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;a6bb303efbbc&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;X&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Runtime&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mf"&gt;0.029982&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;Transfer&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="no"&gt;Encoding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;chunked&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;
&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="no"&gt;Connection&lt;/span&gt; &lt;span class="c1"&gt;#0 to host localhost left intact&lt;/span&gt;
&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;html&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="no"&gt;You&lt;/span&gt; &lt;span class="n"&gt;are&lt;/span&gt; &lt;span class="n"&gt;being&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;href&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="s2"&gt;"https://www.google.com"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;redirected&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/a&amp;gt;.&amp;lt;/&lt;/span&gt;&lt;span class="n"&gt;body&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/html&amp;gt;%
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So with our new-found knowledge, how about making our own &lt;code&gt;redirect_to&lt;/code&gt; behaviour in Rails? All we need to do is set a &lt;code&gt;status&lt;/code&gt; and &lt;code&gt;Location header&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;index&lt;/span&gt;
  &lt;span class="n"&gt;render&lt;/span&gt; &lt;span class="ss"&gt;plain: &lt;/span&gt;&lt;span class="s2"&gt;"You are being redirected to google.com"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="ss"&gt;status: &lt;/span&gt;&lt;span class="mi"&gt;302&lt;/span&gt;
  &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;headers&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'Location'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'https://www.google.com'&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above method also works like &lt;code&gt;redirect_to&lt;/code&gt; but looks a little ugly. But who cares :p&lt;/p&gt;

&lt;p&gt;You can read more about how redirect works here &lt;a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections&lt;/a&gt;&lt;/p&gt;

</description>
      <category>rails</category>
      <category>ruby</category>
      <category>webdev</category>
      <category>beginners</category>
    </item>
    <item>
      <title>what do I need to learn to build a recommendation engine?</title>
      <dc:creator>vamsi pavan mahesh gunturu</dc:creator>
      <pubDate>Sat, 22 Feb 2020 07:03:15 +0000</pubDate>
      <link>https://dev.to/gvpmahesh/what-do-i-need-to-learn-to-build-a-recommendation-engine-1jp9</link>
      <guid>https://dev.to/gvpmahesh/what-do-i-need-to-learn-to-build-a-recommendation-engine-1jp9</guid>
      <description>&lt;p&gt;Hi All, I want to build a recommendation engine at work. For that, I want to understand what technologies are needed to build this kind of stuff.&lt;/p&gt;

&lt;p&gt;I know to build things related to ruby and javascript at the moment.&lt;/p&gt;

&lt;p&gt;There seems to be too much information overload on what to learn in coursera etc. Do I need to learn AI or ML or deeplearning?&lt;/p&gt;

&lt;p&gt;Do I need to have any stat background?&lt;/p&gt;

&lt;p&gt;Would be great if you can help me with a list of MOOCs than books&lt;/p&gt;

&lt;p&gt;Thanks&lt;/p&gt;

</description>
      <category>help</category>
    </item>
    <item>
      <title>Is making 100k USD a big deal from India?</title>
      <dc:creator>vamsi pavan mahesh gunturu</dc:creator>
      <pubDate>Wed, 25 Dec 2019 04:51:39 +0000</pubDate>
      <link>https://dev.to/gvpmahesh/is-making-100k-usd-a-big-deal-from-india-213h</link>
      <guid>https://dev.to/gvpmahesh/is-making-100k-usd-a-big-deal-from-india-213h</guid>
      <description>&lt;p&gt;I have been thinking of picking a remote job by working from Bangalore, India over the next year (2020). There are two aspects that are making remote jobs lucrative to me.&lt;/p&gt;

&lt;p&gt;One is I can work in a peaceful environment. I don't like the noises that are present in the open offices. Given that my domain(Ruby on Rails) is mostly startupy, I have worked only in open offices till now and I think the situation will be the same for the next 5 or so years Until I become a Director or so and can negotiate for an office for myself.&lt;/p&gt;

&lt;p&gt;Second is the money aspect, making 100k per year would change life for me in terms of finances. Currently, I get paid about a little less than 20 k USD in India, and it's decent. I just get by paying bills, mortgage etc. I don't get to have much savings with this amount. But 100 k would change the quality of living dramatically and I get to save a considerable amount for the future.&lt;/p&gt;

&lt;p&gt;So why 100k? I should be paid as per my location right?&lt;/p&gt;

&lt;p&gt;Not really, I would say. I have compared my work with some world-class startups and I would say my work is either comparable if not better. I have built systems that handle millions of requests. I think 100k is not what I would accept if I am in the US. I would be looking at 150 - 200 k which my friends in the US are already making, whom I talk to on a regular basis. So 100k is just a magic number for me, which would make comfortable living in India at this point.&lt;/p&gt;

&lt;p&gt;I have worked remotely in the past like 2 years back, but at that time I did not have significant experience under my belt. And I was a junior. Due to timezone constraints (mostly) and some communication gaps on the expectations end. It did not work out. But this time, I am fully independent, and I won't be needing much help/guidance in taking a feature to production.&lt;/p&gt;

&lt;p&gt;So anyone from India has done this already? How did you go about it? I know India is a huge country and I am pretty sure many people have done it. I just need some help/advice on which companies pay remote employees good wages and how to approach them. I promise I will pay it forward! Any pointers would be great&lt;/p&gt;

&lt;p&gt;Help me, universe!&lt;/p&gt;

&lt;p&gt;Edit:&lt;br&gt;
19th Feb 2020: I reached out to a company that has a remote opening from NewYork. They said timezone is the major constraint even though I seemed like a great fit. Salary was 95k USD. So looks like 100 K USD is doable, it's just that I need to find some company which has a fully async remote culture&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>career</category>
    </item>
    <item>
      <title>Sample in a Range</title>
      <dc:creator>vamsi pavan mahesh gunturu</dc:creator>
      <pubDate>Mon, 23 Dec 2019 06:26:25 +0000</pubDate>
      <link>https://dev.to/gvpmahesh/sample-in-a-range-225i</link>
      <guid>https://dev.to/gvpmahesh/sample-in-a-range-225i</guid>
      <description>&lt;p&gt;I wanted to get a sample from 1 to 10, when I was writing a test case. So as a believer in ruby magic, I just did &lt;code&gt;.sample&lt;/code&gt; on Range &lt;code&gt;1..10&lt;/code&gt;. It did not work! I got this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="mf"&gt;2.5&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mo"&gt;005&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;sample&lt;/span&gt;
&lt;span class="no"&gt;Traceback&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;most&lt;/span&gt; &lt;span class="n"&gt;recent&lt;/span&gt; &lt;span class="n"&gt;call&lt;/span&gt; &lt;span class="n"&gt;last&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;from&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;irb&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;
&lt;span class="no"&gt;NoMethodError&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;undefined&lt;/span&gt; &lt;span class="nb"&gt;method&lt;/span&gt; &lt;span class="sb"&gt;`sample' for 1..10:Range)
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Okay, cool! Maybe there is a random method. So I called .random on the Range. Nope, that did not work either&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="mf"&gt;2.5&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mo"&gt;004&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;
&lt;span class="no"&gt;Traceback&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;most&lt;/span&gt; &lt;span class="n"&gt;recent&lt;/span&gt; &lt;span class="n"&gt;call&lt;/span&gt; &lt;span class="n"&gt;last&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;from&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;irb&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;
&lt;span class="no"&gt;NoMethodError&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;undefined&lt;/span&gt; &lt;span class="nb"&gt;method&lt;/span&gt; &lt;span class="sb"&gt;`random' for 1..10:Range)
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;What, are you serious? This should have been there right? Well, turns out the only way to get this working is by doing &lt;code&gt;rand(1..10)&lt;/code&gt;. But this is not very object-oriented, is it? So how can we make this object-oriented?&lt;/p&gt;

&lt;p&gt;Enter Open Classes, In ruby .. you can open whatever the class the language provides and put your own methods in it, as long as you are not breaking the language&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Range&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;sample&lt;/span&gt;
    &lt;span class="nb"&gt;rand&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;self&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;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now things work as expected&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="mf"&gt;2.5&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mo"&gt;011&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="o"&gt;..&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;sample&lt;/span&gt;
 &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Explanation:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;What did I just do there in the above example?&lt;/p&gt;

&lt;p&gt;I opened &lt;code&gt;Range&lt;/code&gt; class, declared an instance method called &lt;code&gt;sample&lt;/code&gt;. Inside it, I am calling &lt;code&gt;rand&lt;/code&gt; with self as an argument. When you use &lt;code&gt;(1..10)&lt;/code&gt; it's just a syntactic sugar of the representation &lt;code&gt;Range.new(1,10)&lt;/code&gt;. So basically &lt;code&gt;(1..10)&lt;/code&gt; is an instance of the &lt;code&gt;Range&lt;/code&gt; class. Hence by defining an instance method &lt;code&gt;sample&lt;/code&gt;, I made it available to be called on our object &lt;code&gt;(1..10)&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Hope, this cleared things up. Happy programming :)&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>metaprogramming</category>
    </item>
    <item>
      <title>Avoid mutation of variables in ruby by extracting a function</title>
      <dc:creator>vamsi pavan mahesh gunturu</dc:creator>
      <pubDate>Fri, 08 Nov 2019 04:39:21 +0000</pubDate>
      <link>https://dev.to/gvpmahesh/avoid-mutation-of-variables-in-ruby-by-extracting-a-function-24hf</link>
      <guid>https://dev.to/gvpmahesh/avoid-mutation-of-variables-in-ruby-by-extracting-a-function-24hf</guid>
      <description>&lt;p&gt;Let's say you have the code something like this&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;something_else&lt;/span&gt;
  &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;do_something&lt;/span&gt;
  &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;something_else&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;even?&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;x&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is bla bla"&lt;/span&gt; &lt;span class="c1"&gt;# use x for some other operation&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you observe the above code, in the &lt;code&gt;do_something&lt;/code&gt; method. We are mutating the variable x based on something_else. So what's wrong with this?&lt;/p&gt;

&lt;p&gt;The code can become hard to reason about/understand once you start mutating the variables. It can lead to bugs and control flow is not so nice. Maybe we are unable to perceive that pain in this trivial example, but this could become complicated quickly, once you use this approach in something like rails&lt;/p&gt;

&lt;p&gt;So can we make it better? Yes! By extracting the mutation into a function we can write something which is easier to understand and easier to test&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;do_something&lt;/span&gt;
  &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x_value&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;x&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; is bla bla"&lt;/span&gt; &lt;span class="c1"&gt;# use x for some other operation&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;x_value&lt;/span&gt;
  &lt;span class="n"&gt;initial_x_value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
  &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;initial_x_value&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;something_else&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;even?&lt;/span&gt;

  &lt;span class="n"&gt;initial_x_value&lt;/span&gt;
&lt;span class="k"&gt;end&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;By extracting the &lt;code&gt;x_value&lt;/code&gt; method, we removed the mutation completely from &lt;code&gt;do_something&lt;/code&gt; method and it's somewhat easier to follow than tracking what happened to variable x at this point. The bonus is you can easily test the &lt;code&gt;x_value&lt;/code&gt; independently without depending on testing &lt;code&gt;do_something&lt;/code&gt; method&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>functional</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
