Live Refactoring with Joe

Live Refactoring with Joe In this episode, Chris is joined by thoughtbot CTO Joe Ferris. With the magic of live-coding, Joe demonstrates how a simple Extract Class refactoring can lead to a host of code improvements. You can see the full change...
This is a companion discussion topic for the original entry at

Thanks for the episode!

I’m not sure if it’s easily fixable, but the video intro has a small typo (“Reafactoring”) :smile:

BTW, the site linked to in the show notes is built from stolen content (see

Hey @andyw8, thanks as always for your comments. We’ve updated the video and updated the link to point at as a more canonical source for the refactoring summary.


– Chris

The private class technique by @jferris stood out to me. However, playing around with it some it seems that the Payload class would still be publicly accessible. For example:

> class Foo
 *   private
 *   class Bar
 *   end
 * end
=> nil
=> #<Foo::Bar:0x007f987a5a62b0>

However, using private_constant keeps the class private.

 > class Foo
 *   class Bar
 *   end
 *   private_constant :Bar
 * end
=> Foo < Object
2.2.4 (main):0 >
=> NameError: private constant Foo::Bar referenced

I know this wasn’t the main point of this weekly iteration, but I was curious if doing it the way in the video had any benefits. It doesn’t appear to keep the class private. Perhaps it worked some point? I was using ruby 2.3 so maybe it changed recently?

@DavidVII thanks for calling that out!

I tend to put “private” classes at the bottom, below the private keyword. This isn’t because it makes them inaccessible, but because I try to put high-level details at the top of each file, and place internal/implementation code towards the bottom. This way, the file starts out as an abstract declaration of what’s going to happen, and the details are explained in depth as you continue into the file.

I frequently forget that these classes are still public, but I avoid referencing these internal classes anyway out of habit. I’ve started using private_constant in newer code to prevent accidental misuse, but the habit isn’t fully formed yet.

@jferris Thanks for clarifying :slight_smile: