Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor handle_command / no more switch statement #26

Merged
merged 1 commit into from
Dec 28, 2023

Conversation

benjaminwood
Copy link
Contributor

Given that each command has a corresponding handle_* method, we don't really need a switch statement. We can just call the methods dynamically and rescue the NoMethodError. This makes it easier to handle new commands in the future by simply adding a new handle_* method.

I've also refactored how we break the main loop in the test scenario. Instead of returning true/false, a command can explicitly return :break.

Given that each command has a corresponding handle_ method, we don't
really need a switch statement. We can just call the methods dynamically
and rescue the NoMethodError. This makes it easier to handle new commands
in the future by simply adding a new handle_ method.

I've also refactored how we break the main loop in the test scenario.
Instead of returning true/false, a command can explicitly return :break.

Co-authored-by: Nate Vick <nate.vick@hint.io>
@benjaminwood benjaminwood self-assigned this Dec 27, 2023
@benjaminwood benjaminwood mentioned this pull request Dec 27, 2023
Copy link
Contributor

@natevick natevick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet!

@benjaminwood benjaminwood merged commit da8d683 into main Dec 28, 2023
4 checks passed
@benjaminwood benjaminwood deleted the refactor-handle-command branch December 28, 2023 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants