<?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: Hasan Tanbir</title>
    <description>The latest articles on DEV Community by Hasan Tanbir (@hmtanbir).</description>
    <link>https://dev.to/hmtanbir</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%2F640258%2Fe23a80ef-c40c-474b-a4ca-b85dd8a4516b.png</url>
      <title>DEV Community: Hasan Tanbir</title>
      <link>https://dev.to/hmtanbir</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hmtanbir"/>
    <language>en</language>
    <item>
      <title>Rails 7 introduces a new debugging gem</title>
      <dc:creator>Hasan Tanbir</dc:creator>
      <pubDate>Fri, 12 Nov 2021 16:05:13 +0000</pubDate>
      <link>https://dev.to/hmtanbir/-17ic</link>
      <guid>https://dev.to/hmtanbir/-17ic</guid>
      <description>&lt;p&gt;We commonly use &lt;a href="https://github.com/deivid-rodriguez/byebug"&gt;byebug&lt;/a&gt; for debugging our code which is an easy-to-use, feature-rich ruby debugger. This gem is introduced in Rails 5.  It offers features like &lt;code&gt;Stepping&lt;/code&gt;, &lt;code&gt;Breaking&lt;/code&gt;, &lt;code&gt;Evaluating&lt;/code&gt; and &lt;code&gt;Tracking&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We can easily control the execution of a program and the debug inspector for call stack navigation. It allows us to control and the execution flow.&lt;/p&gt;

&lt;p&gt;We can found this &lt;a href="https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-byebug-gem"&gt;documentation&lt;/a&gt; for installing byebug with ruby's most popular framework ruby on rails which was marged in this &lt;a href="https://github.com/rails/rails/pull/14646"&gt;pull request&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But Rails 7 is replacing byebug with ruby's own gem &lt;a href="https://github.com/ruby/debug"&gt;debug&lt;/a&gt; which was merged in this &lt;a href="https://github.com/rails/rails/pull/43187"&gt;pull request&lt;/a&gt; on Sep 8, 2021.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/ruby/debug"&gt;debug&lt;/a&gt; is Ruby's debug mechanism which will be included in Ruby 3.1 version.&lt;/p&gt;

&lt;p&gt;So, to adjust Rails with Ruby &lt;code&gt;debug&lt;/code&gt; has been introduced in Rails 7.&lt;/p&gt;

&lt;p&gt;Let's compare some example of debugging with &lt;code&gt;byebug&lt;/code&gt; and new &lt;code&gt;debug&lt;/code&gt; gem.&lt;/p&gt;

&lt;h3&gt;
  
  
  Before
&lt;/h3&gt;

&lt;p&gt;Let's assume we have a controller named &lt;code&gt;UserController&lt;/code&gt;. Inside any Rails application, we can call the debugger by calling the &lt;code&gt;byebug&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# app/controllers/user_controller.rb

class UserController &amp;lt; ApplicationController
  def index
    name = "Hasan Tanbir"
    byebug # Call to debugger
    country = "Bangladesh"
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Invoked debugger results will be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    [1, 7] in app/controllers/user_controller.rb
    1: class UserController &amp;lt; ApplicationController
    2:   def index
    3:     name = "Hasan Tanbir"
    4:     byebug # Call to debugger
=&amp;gt;  5:    country = "Bangladesh"
    6:   end
    7: end

  (byebug) name # variable call
  "Hasan Tanbir"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  After
&lt;/h3&gt;

&lt;p&gt;When we use &lt;code&gt;debug&lt;/code&gt; in Rails 7, we will have to use &lt;code&gt;binding.break&lt;/code&gt; method instead of &lt;code&gt;byebug&lt;/code&gt; method.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;# app/controllers/user_controller.rb

class UserController &amp;lt; ApplicationController
  def index
    name = "Hasan Tanbir"
    binding.break # Call to debugger
    country = "Bangladesh"
  end
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Invoked debugger results will be:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    [1, 7] in app/controllers/user_controller.rb
    1: class UserController &amp;lt; ApplicationController
    2:   def index
    3:     name = "Hasan Tanbir"
    4:     byebug # Call to debugger
=&amp;gt;  5:    country = "Bangladesh"
    6:   end
    7: end
&amp;gt;#0 UserController#index at ~/demo_app/app/controllers/user_controller.rb:5 

  (rdbg) name # variable call
  "Hasan Tanbir"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can check out the &lt;a href="https://github.com/rails/rails/pull/43187"&gt;pull request&lt;/a&gt; for more details and for commands or features of &lt;a href="https://github.com/ruby/debug"&gt;Ruby/debug&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
      <category>byebug</category>
      <category>debug</category>
    </item>
    <item>
      <title>Remove blank values easily in Rails 6.1</title>
      <dc:creator>Hasan Tanbir</dc:creator>
      <pubDate>Sun, 30 May 2021 11:11:00 +0000</pubDate>
      <link>https://dev.to/hmtanbir/remove-blank-values-easily-in-rails-6-1-pdf</link>
      <guid>https://dev.to/hmtanbir/remove-blank-values-easily-in-rails-6-1-pdf</guid>
      <description>&lt;p&gt;Rails 6.1 adds &lt;code&gt;compact_blank&lt;/code&gt; and &lt;code&gt;compact_blank!&lt;/code&gt; methods to &lt;code&gt;ActiveSupport&lt;/code&gt;. It makes easier for removing blank or nil values from an Enumerable ActionController::Parameters.&lt;/p&gt;

&lt;p&gt;Here is the &lt;a href="https://github.com/rails/rails/pull/36412"&gt;pull request&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Before Rails 6.1.0
&lt;/h3&gt;

&lt;p&gt;We can remove blank values from an array as like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[1,nil,'',:bar].reject(&amp;amp;:blank?)
# [1,:bar]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can remove blank values from a hash as like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{ x: nil, y:[], z: :bar }.reject{|key,value| value.blank? }
# { :z =&amp;gt; :bar }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  After Rails 6.1
&lt;/h3&gt;

&lt;p&gt;we can use &lt;code&gt;compact_blank&lt;/code&gt; and &lt;code&gt;compact_blank!&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;Array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[1,nil,'',:bar].compact_blank
# [1,:bar]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hash:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{ x: nil, y:[], z: :bar }.compact_blank
# { :z =&amp;gt; :bar }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can use &lt;code&gt;compact_blank!&lt;/code&gt; which mutates it's receiver:&lt;/p&gt;

&lt;p&gt;Array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;array = [1, "", nil,2, " ", [], {}, true, false]
array.compact_blank!
# [1,2,true]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Hash:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;hash = { a: 1, b: "", c: nil, d:"string", e:" ", f:[], g:{}, h: true, i: false }
hash.compact_blank!

# { :a =&amp;gt; 1, :d =&amp;gt; "string", :h =&amp;gt; true }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>rails</category>
      <category>ruby</category>
      <category>activesupport</category>
    </item>
  </channel>
</rss>
