Tuesday 11 December 2012

Rails App Composer

Of late, I have grown very fond of the Rails app composer gem. I don't think it has too much magic, as I have heard some Rails devs say. Actually, I do not think it has any magic at all! You simply create recipes and use them. That's it!

Run this code to set something up interactively and see a list of common recipes. I do not see why anyone should start a Rails 3 app any other way.

Sunday 9 December 2012

Code is a reflection of your dev team's Communication

I have always been a great campaigner for effective communication among developers. This RailsConf 2012 presentation is on my side. Team leads/devs, check it out.


Thursday 6 December 2012

FizzBuzz

I finally wrote a Ruby solution to FizzBuzz. Here is my solution on GitHub which I came up with in five minutes. I'll  do some refactoring to have cleaner methods. Have a look and feel free to send a pull request if think your OO design is better  ;)

Wednesday 5 December 2012

Array#select makes me happy

Array#select makes me happy. Ruby was my first programming language and our marriage is going strong. I could compare #select to methods in other (not as awesome) languages, but I  choose not to. 

This is all I'll say, all you non-Rubyists out there, this is what you are missing: 

array_one = [1, 2, 3, 4, 5]
array_two = array_one.select { |a| a > 2 }

Select iterates through array_one picking the items in the array that return true to the condition passed into #select block.

1.9.3p286 :004 > array_one = [1, 2, 3, 4, 5]
 => [1, 2, 3, 4, 5] 
1.9.3p286 :005 > array_two = array_one.select { |a| a > 2 }
 => [3, 4, 5] 
1.9.3p286 :006 >

Monday 3 December 2012

Ruby on Rails: ERB Makes My Eyes Bleed

Ruby on Rails: ERB Makes My Eyes Bleed: I'm sure it makes your eyes bleed too, even if you haven't realized this yet. Start using  Haml , now! Here's a snippet from my navigation p...

ERB Makes My Eyes Bleed

I'm sure it makes your eyes bleed too, even if you haven't realized this yet. Start using Haml, now! Here's a snippet from my navigation partial from a Rails app to convince you to make the shift.


- if !user_signed_in? && !client_user_signed_in?
    %li#client-login
      = link_to 'Shopper Login', new_client_user_session_path
    %li#client-signup
      = link_to 'Shopper Sign Up', new_client_user_registration_path
    %li#admin-login
      = link_to 'I am Admin', new_user_session_path

Now let me write the same (not good) code in erb:


<% if !user_signed_in? && !client_user_signed_in? %>
    <li id="client-login"> 
      <%= link_to 'Shopper Login', new_client_user_session_path %>
    </li>
    <li id="client-signup">
      <%= link_to 'Shopper Sign Up', new_client_user_registration_path %>
    </li>
    <li id="admin-login">
      <%= link_to 'I am Admin', new_user_session_path %>
    </li>

Let the code speak for itself!