acts_as_list refactoring part 3

In this article I’m continuing refactoring acts_as_list gem I started in part 2 and part 1. You don’t need to read either part to understand this article. acts_as_list is a Rails gem. It allows you to treat Rails model records as part of an ordered list and offers methods like #move_to_bottom and #move_higher. In this refactoring adventure I’m going to focus on just one 11-line method, and surprisingly, there’s a lot of things that can be improved in just

Continue Reading

acts_as_list refactoring part 2

In this post I’m continuing refactoring of acts_as_list gem I started in part 1. As you might remember, I’ve split .acts_as_list method into several modules, each module dedicated to an option passed to the method. E.g. ColumnMethodDefiner module defines methods related to the column option (the option defines column name for storing record’s list position). This post is dedicated to refactoring of the ColumnMethodDefiner module. Improving ColumnMethodDefiner module So, I’ve extracted code related to column option of .acts_as_list to

Continue Reading

Be lazy and don’t keep context in your head

Sometimes, code we read makes us to remember context. Consider the following code (it sends an invite email to a user): Lines 2-8 (see above ↑) deal with the case of existing user, and the rest deal with the case of new user. When reading lines 3-5 you have to remember that you’re dealing with an existing user, same with lines 12-22, only there you deal with a new user. After all, both existing user and new user cases

Continue Reading

Site Footer

Web Analytics