DEV Community

Discussion on: Refactoring checklist for beautiful Ruby code

Collapse
 
marcelolipienski profile image
Marcelo Lipienski

Congratz! These are really helpful tips. I hope you don't mind me sharing a few more :)

The second tip features an example that realistically would be better solved by introducing a Value Object, but it is still a good example on how to clean up your code by replacing simple if/else with ternary operator.

To learn more about Value Objects, you can check out this article.

For the ninth tip, personally I would also drop the usage of [-1] syntax.
Imagine you're code pairing and you're telling your partner that they should pick the last element.

You see? It's easier to read through a code that is written kind of the way we are used to speak. So elements.last reads much better than elements[-1].

Collapse
 
junko911 profile image
Junko T.

Hi Marcelo, thank you so much for your suggestions!

I didn't know about Value Objects. This article is really helpful.

Also, I was actually thinking about dropping [-1] syntax from the ninth item. I decided to keep it as another option but your explanation really makes sense. I might be going to update my article.

Thank you, again!