Refactoring: Ruby Edition by Jay Fields

By Jay Fields

The Definitive Refactoring consultant, totally made over for Ruby

 

With refactoring, programmers can remodel even the main chaotic software program into well-designed structures which are a ways more uncomplicated to conform and preserve. What’s extra, they could do it one step at a time, via a chain of straightforward, confirmed steps. Now, there’s an authoritative and broadly up-to-date model of Martin Fowler’s vintage refactoring publication that makes use of Ruby examples and idioms throughout–not code tailored from Java or the other environment.

 

The authors introduce a close catalog of greater than 70 confirmed Ruby refactorings, with particular counsel on whilst to use every one of them, step by step directions for utilizing them, and instance code illustrating how they paintings. a number of the authors’ refactorings use robust Ruby-specific positive aspects, and all code samples can be found for obtain.

 

Leveraging Fowler’s unique suggestions, the authors convey find out how to practice refactoring in a managed, effective, incremental demeanour, so that you methodically increase your code’s constitution with no introducing new insects. no matter what your position in writing or preserving Ruby code, this publication should be an vital source.

 

This publication can assist you

•    comprehend the middle ideas of refactoring and the explanations for doing it

•    realize “bad smells” on your Ruby code

•    remodel undesirable designs into well-designed code, one step at a time

•    construct checks to ensure your refactorings paintings properly

•    comprehend the demanding situations of refactoring and the way they are often overcome

•    Compose how to package deal code properly

•    circulation gains among items to put tasks the place they healthy most sensible

•    set up facts to provide help to paintings with

•    Simplify conditional expressions and make greater use of polymorphism

•    Create interfaces which are more straightforward to appreciate and use

•    Generalize extra effectively

•    practice higher refactorings that rework whole software program platforms and will take months or years

•    effectively refactor Ruby on Rails code

Show description

Read Online or Download Refactoring: Ruby Edition PDF

Similar systems analysis & design books

Architectures for E-Business Systems: Building the Foundation for Tomorrow's Success

As dot. com businesses grapple with inflexible industry stipulations and we retain listening to how the massive know-how gamers are being punished on Wall road, it turns into effortless to consider the web as a fad. the web frenzy can have subsided, yet curiosity within the web as a company and advertising and marketing software remains to be powerful.

Operating System Concepts, 6th Edition

Celebrating its twentieth anniversary, Silberschatz: working platforms strategies, 6th version, maintains to supply a superior theoretical starting place for realizing working structures. The 6th version bargains more advantageous conceptual insurance and extra content material to bridge the distance among recommendations and real implementations.

Extra info for Refactoring: Ruby Edition

Sample text

I am now at the point where I take off my refactoring hat and put on my adding function hat. to_s + "
\n" end # add footer lines result += "

You owe #{total_charge}

\n" result += "On this rental you earned " + "#{total_frequent_renter_points} " + "frequent renter points

" result end end By extracting the calculations I can create the html_statement method and reuse all of the calculation code that was in the original statement method. I didn’t copy and paste, so if the calculation rules change I have only one place in the code to go to.

I can now test to see whether this method works. amount_for to delegate to the new method. charge end end I can now test to see whether I’ve broken anything. to_s + "\n" total_amount += this_amount end # add footer lines result += "Amount owed is #{total_amount}\n" result += "You earned #{frequent_renter_points} frequent renter points" result end end From the Library of Lee Bogdanoff Decomposing and Redistributing the Statement Method In this case this step is easy because we just created the method, and it is in only one place.

If I change the movie type, I want the least ripple effect, so I prefer to calculate the charge within the movie. charge(days_rented) end end From the Library of Lee Bogdanoff 34 Replacing the Conditional Logic on Price Code with Polymorphism Chapter 1 Refactoring, a First Example Once I’ve moved the charge method, I do the same with the frequent renter point calculation. price_code == Movie::NEW_RELEASE && days_rented > 1) ? 12 Class diagram before moving methods to movie. frequent_renter_points(days_rented) end end 35 Replacing the Conditional Logic on Price Code with Polymorphism class Movie def frequent_renter_points(days_rented) (price_code == NEW_RELEASE && days_rented > 1) ?

Download PDF sample

Rated 4.17 of 5 – based on 39 votes