Need suggestions to refactor my code

Hello folks, I am a budding ruby developer/enthusiast.
Though not well versed with Ruby way of coding, I have been catching up lately to write efficient and ruby-way program. I am currently working on refactoring my code which was written hurriedly to get the job done at the initial stage. Though I have re-written/refactored 50% of my code, I am stuck with rest needing better ideas. Can somebody review my code or provide any ruby code-review websites?

1 Like

The majority of video clips shared in Awesome conference talks teach and show better coding practices. At least one is specifically focused on refactoring. I also a fan of Jim Weirich’s Roman Numeral Kata which he has demonstrated on Youtube. I get my refactorings ideas from videos, blogs, and reading other peoples code on CodeWars; after a kata is solved every one elses solution for it is visible.

You can also pair program with others. That’s an optimal way to grow and learn.

You can find some blogs to follow over at What does your Tech Podcast/RSS Feed Subscription List look like?

1 Like

I would read some Ruby books - Eloquent Ruby (by the amazing Russ Olsen) is probably a good start for you.

I keep meaning to re-read it! :043:

1 Like

I also like answering StackOverflow questions. Every time I do I spend a good chunk of time refactoring my solution into a better one.

I have been following Sandy Metz’s approach as shown in this video to refactor my code.

All the Little Things by Sandi Metz

Initially I was able to refactor my code into smaller classes, removing code blocks that were being used frequently, making them common methods and moving the conditions from main actions. But later I got stuck whilst trying to refactor a code block that was dealing with multiple complex hashes.

1 Like

Thanks for the tip. Would download the book “Eloquent Ruby”.
Cheers!

I hope by that you mean you’ll buy it - books like Eloquent Ruby are far more valuable than the $20 or so cost :slight_smile:

$20 ?? I cannot afford one though rightnow :sweat:

For Rails I ve been using this free online copy

Michael Hartl - Rails Tutorial

And for Ruby
Learn Ruby the Hard Way

And I think I do have a free text copy of Beginning Ruby

Wish free online copies are available for Eloquent Ruby

I don’t recommend “steeling” anything. There are *free Ruby books available (with the two you’ve listed):

Most of these books are quite dated; a bit old.

Why’s book is a bit fun to read. The amount of free stuff available for Ruby is great. There’s no reason to deprive authors of any earnings by taking books that have a cost. For that I recommend a used book store, or Amazon used books. I know a place in VA, USA that you can get most books for $4.

The most beneficial resources for me have largely been conference talks via Confreaks

1 Like

There’s also the library, eBay etc :smile:

Book authors don’t make a great deal of money - the more sales they get the more likely they are to write more. This is SO important when you have gifted writers like Russ Olsen - it would be a terrible shame and a huge loss to us if he stopped writing.

1 Like

I completely agree with you… Ruby is great and there is no reason to deprive authors of their earnings…

I am a self taught amateur developer and those online resources have helped me a lot. But the price of Ruby Books (Mostly from foreign publications) costs a bomb, due to the currency conversion rates and comparatively low wages…

And most of the private and academic libraries here are filled with Java and C# books. A Ruby book is hard to find here…

Wish big publications make their books affordable.
Between who is Russ Olsen? :confused:

New Ruby Rogues podcast! Refactoring