<?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: Dāvis Namsons</title>
    <description>The latest articles on DEV Community by Dāvis Namsons (@dnamsons).</description>
    <link>https://dev.to/dnamsons</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%2F97049%2Fe79f688b-b991-4bf8-aadd-eee078c1e626.jpeg</url>
      <title>DEV Community: Dāvis Namsons</title>
      <link>https://dev.to/dnamsons</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dnamsons"/>
    <language>en</language>
    <item>
      <title>Debugging Ruby in VS Code</title>
      <dc:creator>Dāvis Namsons</dc:creator>
      <pubDate>Tue, 25 Sep 2018 18:21:47 +0000</pubDate>
      <link>https://dev.to/dnamsons/ruby-debugging-in-vscode-3bkj</link>
      <guid>https://dev.to/dnamsons/ruby-debugging-in-vscode-3bkj</guid>
      <description>&lt;p&gt;Although &lt;code&gt;binding.pry&lt;/code&gt; is adequate for simple debugging purposes, I find that for cases when I have to quickly see multiple variable and object values, it becomes time consuming and messy. Thus I &lt;br&gt;
use vscode's built-in debugging features with the &lt;a href="https://github.com/ruby-debug/ruby-debug-ide" rel="noopener noreferrer"&gt;ruby debug ide&lt;/a&gt; interface. Here's how to set it up:&lt;/p&gt;

&lt;h2&gt;
  
  
  Install the required gems
&lt;/h2&gt;

&lt;h3&gt;
  
  
  For JRuby or Ruby v1.8.x
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gem install ruby-debug-ide
gem install ruby-debug-base
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  For Ruby v1.9.x
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gem install ruby-debug-ide
gem install ruby-debug-base19x
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  For Ruby v2.x
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;gem install ruby-debug-ide
gem install debase
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Create a &lt;code&gt;launch.json&lt;/code&gt; file
&lt;/h2&gt;

&lt;p&gt;If you don’t have it yet, install the &lt;a href="https://marketplace.visualstudio.com/items?itemName=rebornix.Ruby" rel="noopener noreferrer"&gt;Ruby&lt;/a&gt; extension and reload the editor.&lt;/p&gt;

&lt;p&gt;In vscode, open the debugging tab and click on the dropdown, then choose the &lt;code&gt;Add configuration...&lt;/code&gt; option.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnhdnjhnt15rb996bhcd6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnhdnjhnt15rb996bhcd6.png" alt="selecting 'Add Configuration in the debug view'" width="727" height="487"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select &lt;code&gt;Ruby&lt;/code&gt; from the new dropdown menu. This will create a &lt;code&gt;.vscode&lt;/code&gt; folder with a &lt;code&gt;launch.json&lt;/code&gt; file in your current directory.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frg28h76oy56i3ywyiil3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frg28h76oy56i3ywyiil3.png" alt="Selecting Ruby as the configuration" width="800" height="171"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Launch a debugging session
&lt;/h2&gt;

&lt;p&gt;Now you can run the &lt;code&gt;rdebug&lt;/code&gt; interface in your terminal:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rdebug-ide --host 0.0.0.0 --port 1234 --dispatcher-port 26162 /path/to/the/file.rb&lt;/code&gt;&lt;br&gt;
(In case you need to change the port, remember to specify it in &lt;code&gt;launch.json&lt;/code&gt; as well)&lt;/p&gt;

&lt;p&gt;If you're trying to debug a Rails app, you should instead specify the path of the rails script in your project with the &lt;code&gt;server&lt;/code&gt; command. The script is usually located in the &lt;code&gt;bin&lt;/code&gt; directory of your project, in which case you would write it as &lt;code&gt;bin/rails server&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;After the interface is running in the terminal, you can start the debugging session. In the debug tab choose &lt;code&gt;Listen for rdebug-ide&lt;/code&gt; from the dropdown menu. Click the start button. &lt;/p&gt;

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

&lt;p&gt;Your debugging session should be running. You can now hit your set breakpoints and use the debugging console to help analyse your Ruby code.&lt;/p&gt;

&lt;p&gt;Here's an example:&lt;/p&gt;

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

&lt;p&gt;Happy debugging!&lt;/p&gt;

</description>
      <category>vscode</category>
      <category>ruby</category>
      <category>rails</category>
      <category>debugging</category>
    </item>
  </channel>
</rss>
