Hacker News new | ask | show | jobs
by Lio 299 days ago
I'll leave aside the unnecessary test for parity as contrived for the example.

This is a question of style; it's possible to write ruby the way you have but with experience you definitely wouldn't.

e.g.

Why wrap the iterator in an if..else..end block? You could replace that with a one line guard statement at the top of the method. No end required.

Why use begin..rescue..end in the middle of your example? Just replace that with a single rescue at the end of the method. Again, no end statement required.

This is like nesting 20 if..else blocks in python and then complaining you don't have a monitor big enough to view it without scrolling. You just wouldn't do it that way.

My hope is that with the new ruby parser rubocop will be more agressive about automatically refactoring examples like this away.