<?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: Akshay Birajdar</title>
    <description>The latest articles on DEV Community by Akshay Birajdar (@thespectator).</description>
    <link>https://dev.to/thespectator</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%2F270917%2F8f3ccaa3-33c9-4804-bd1d-363271e4bac3.jpeg</url>
      <title>DEV Community: Akshay Birajdar</title>
      <link>https://dev.to/thespectator</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/thespectator"/>
    <language>en</language>
    <item>
      <title>Should Gem assumes that other gem is loaded?</title>
      <dc:creator>Akshay Birajdar</dc:creator>
      <pubDate>Fri, 23 Oct 2020 12:21:27 +0000</pubDate>
      <link>https://dev.to/thespectator/should-gem-assumes-that-other-gem-is-loaded-2a03</link>
      <guid>https://dev.to/thespectator/should-gem-assumes-that-other-gem-is-loaded-2a03</guid>
      <description>&lt;p&gt;We have a gem where we have a method &lt;code&gt;#display_name&lt;/code&gt;, this method returns localized name if I18n gem is defined else falls back to default_display_name.&lt;/p&gt;

&lt;p&gt;Following is the current implementation:&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;display_name&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="no"&gt;Module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;const_defined?&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:I18n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
      &lt;span class="n"&gt;localized_display_name&lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;
      &lt;span class="n"&gt;default_display_name&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;We want to refactor it as on every method call we are calling &lt;code&gt;Module#const_defined?&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Following is the proposed implementation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="no"&gt;Module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;const_defined?&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="ss"&gt;:I18n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;display_name&lt;/span&gt;
    &lt;span class="n"&gt;localized_display_name&lt;/span&gt;
  &lt;span class="k"&gt;end&lt;/span&gt;
&lt;span class="k"&gt;else&lt;/span&gt;
  &lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;display_name&lt;/span&gt;
    &lt;span class="n"&gt;default_display_name&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;On surface level this looks ok but we have a concern that now we are assuming the require order of gem. So, my question is, should the gem assume the other gem is loaded (in this case I18n) or it should lazily checks like current implementation.&lt;/p&gt;

&lt;p&gt;And any other suggestions for refactoring/optimizations are welcome. Thanks in advance!&lt;/p&gt;

</description>
      <category>ruby</category>
      <category>rails</category>
    </item>
    <item>
      <title>Making Your Rails Console Interesting..</title>
      <dc:creator>Akshay Birajdar</dc:creator>
      <pubDate>Wed, 15 Jan 2020 09:47:49 +0000</pubDate>
      <link>https://dev.to/thespectator/making-your-rails-console-interesting-pdc</link>
      <guid>https://dev.to/thespectator/making-your-rails-console-interesting-pdc</guid>
      <description>&lt;p&gt;As a Rails developer, every time we work on a Rails project we heavily use rails console for development. I love the rails console as much as any Rails developer. It is the best place to experiment or validate your logic but...!&lt;/p&gt;

&lt;p&gt;There are some of my personal nit-picks:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;When we are playing around with multiple rails projects and end up opening rails console for multiple projects, then it becomes difficult to identify which rails console belong to which project.&lt;/li&gt;
&lt;li&gt;Another problem with these &lt;em&gt;plain&lt;/em&gt; rails console is identifying the rails environment in which we are. Until you run &lt;code&gt;Rails.env&lt;/code&gt; you can't be sure.&lt;/li&gt;
&lt;li&gt;But the biggest issue with the &lt;em&gt;plain old&lt;/em&gt; rails console is; it is &lt;strong&gt;BORING!&lt;/strong&gt; It's the same old screen every time I open.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Your rails console should be more declartive&lt;/p&gt;

&lt;h2&gt; &lt;center&gt; Enter the Dotfiles &lt;/center&gt;
&lt;/h2&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ffjsok0yoffci13t3kn89.jpg" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Ffjsok0yoffci13t3kn89.jpg" alt="Time To spice things up"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A little while ago I came to know about dotfiles by &lt;a href="https://www.youtube.com/watch?v=V0p7pWSxOXw" rel="noopener noreferrer"&gt;Rails conf talk&lt;/a&gt; by &lt;a href="https://twitter.com/bradurani" rel="noopener noreferrer"&gt;@bradurani&lt;/a&gt;. So basically the dotfiles are the configuration for Unix-y systems. In our daily dev life we use .bashrc, .bash_profile etc.&lt;br&gt;
 To my surprise ruby's IRB also has dotfile based configuration &lt;strong&gt;.irbrc&lt;/strong&gt; and rails console is based on IRB so this config does apply to rails console too.&lt;/p&gt;

&lt;p&gt;In this blog post, we will explore .irbrc prompt configuration and tackle the issues mentioned above.&lt;/p&gt;

&lt;p&gt;IRB provides many prompt modes out of the box, these are &lt;strong&gt;NULL&lt;/strong&gt;, &lt;strong&gt;DEFAULT&lt;/strong&gt;, &lt;strong&gt;CLASSIC&lt;/strong&gt;, &lt;strong&gt;SIMPLE&lt;/strong&gt;, etc.&lt;br&gt;
To switch between these prompt-modes, edit your .irbrc (located in HOME directory, if it's not present, create it.)&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F4rq4isqm4q3c259mtp5l.gif" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F4rq4isqm4q3c259mtp5l.gif" alt="Simple IRB Prompt"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There's a lot we need to understand before the above configuration starts making sense.&lt;/p&gt;

&lt;p&gt;1 . Specific format for the irb prompt is used:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;2 . Special strings are provided in irb as prompt-helpers:&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now, let's take a look at how IRB defines Classic mode &amp;amp; Simple mode.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Hurray!!, we completed the basic guide, now lets start tweaking with our &lt;strong&gt;.irbrc&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Let's target our first issue, "How to inform the developer about the rails application name in the rails console?"&lt;/p&gt;

&lt;p&gt;The first step, get the application name in rails.&lt;/p&gt;

&lt;p&gt;We can find our rails app name in &lt;code&gt;config/application.rb&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Note: We will be using meetup rails app for examples&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight ruby"&gt;&lt;code&gt;

&lt;span class="c1"&gt;# config/application.rb&lt;/span&gt;

&lt;span class="k"&gt;module&lt;/span&gt; &lt;span class="nn"&gt;Meetup&lt;/span&gt;
  &lt;span class="k"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Application&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="no"&gt;Rails&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="no"&gt;Application&lt;/span&gt;
  &lt;span class="o"&gt;...&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
  &lt;span class="nf"&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;Notice that our application name is the module name for rails application class, now let's get it programmatically.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;Now let's tackle the second issue, Rails environment information in rails console this is straightforward...&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;Now let's glue these together with .irbrc&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fb5puyceh6qqp0wdx9axp.gif" 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%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fb5puyceh6qqp0wdx9axp.gif" alt="Stitched irbrc"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Oh! Wait we still haven't solved the important issue. Its still &lt;strong&gt;BOORING&lt;/strong&gt; plain rails console.&lt;br&gt;
Since &lt;strong&gt;irbrc&lt;/strong&gt; is just ruby, your imagination is only the limitation for making it interesting. Following are my version of rails console's&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Colorful rails console using Rainbow gem or ANSI escape codes
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fmx556wm981muglmz6wpd.gif" alt="Color rails console"&gt;
&lt;/li&gt;
&lt;li&gt;Rails console with emojis
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;

&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F8ulj03ohvfuv3kjdn1ca.gif" alt="Emoji"&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Thank you for reading!!&lt;/p&gt;

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