Recently, I didn’t have time or resource for serious writing. I had plans for several long articles for the summer that gone, but unfortunately not

“Gilded Rose” refactoring kata in Ruby — as if it is 2024

submited by
Style Pass
2024-09-19 11:30:06

Recently, I didn’t have time or resource for serious writing. I had plans for several long articles for the summer that gone, but unfortunately not many have came of that. But last night I have stumbled upon famous (so it seems, though I have never seen it before) refactoring kata, and had an impulse for trying my hands on that, writing down some thoughts on my ways of writing code along the way.

Feel free to make any changes to the UpdateQuality method and add any new code as long as everything still works correctly. However, do not alter the Item class.

The initial Ruby implementation provided by the kata maintainer is some scary 45-line method, all made of ifs with many levels of nesting; it is a direct translation of the initial C# implementation. The suggested exercise is to refactor it in any way one sees suitable.

Several Ruby solutions to the kata can be found throughout the internet. Mostly, they take on the usual path of having a class per every item kind and frequently divide all the logic into five-word-name, one-line-body methods for each action in every class: that’s a style significant part of the community prefers lately.

Leave a Comment