How do I refactor lines of Ruby code that run too long due to method chaining or object instantiation?
I don't really see any real trouble with those lines. But I know the feeling that a line just seems "too long" (especially if everything else in the file is nice and neat). It's often a good thing to notice, but in some cases it just doesn't make sense to worry.

Are the lines readable? Absolutely. They are very descriptive in fact. If you were talking about a very long conditional filled with &amp;&amp; and || and negations, then yeah, it should probably be changed. But in this case, I don't see reason to fret.

But if you're intent on refactoring, you could (as an example) move the ArraySerializer instantiation into a factory on DepartmentWithLocationSerializer and get something like

DepartmentWithLocationSerializer.serialize(scope).as_json


That sort of thing helps a bit. But if I knew a good zen quote about a little imperfection being OK too, I'd drop it here :)

Anyway, don't worry about adding methods for things you'll only use once. You don't always need a very "practical" reason like DRY, to add some more methods. If adding some methods it can make the code a little neater to look at, that's a reason in itself. Everything in moderation, YMMV, etc., so just try it out and see if the code seems nicer afterwards. If it doesn't, well, then try to live with the long lines.