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

🌈 Fixes a bug in the calculation of the print_wrapped method #719

Merged
merged 1 commit into from
Mar 13, 2020

Conversation

sergio-bobillier
Copy link

Description

This pull request fixes a bug that caused the print_wrapped method in the Thor::Shell::Basic class to incorrectly wrap the text when printing on the terminal. The reason for the bug is that the method assumes that the loop starts with the first word, when in fact it starts with the second word and the first word is already in the memo variable.

Before the change:

Screen Shot 2020-03-12 at 16 56 39

After the change

Screen Shot 2020-03-12 at 16 57 09

To see why this occurs you can run the following code on IRB or PRY:

>%w[hello world! how are you doing].inject { |memo, word| puts "#{memo} : #{word}"  }
hello : world!
 : how
 : are
 : you
 : doing
=> nil

As you can see the first iteration already has "hello" in memo and the first word is actually "word!". The print_wrapped was not accounting for this and therefore given the right conditions the method would print beyond the edge of the terminal.

Fixes a bug that was causing the print_wrapped method to incorrectly
wrap the text and print beyond the edge of the terminal.

The reason for the bug is that the function assumed that the iteration
started with the first word but it actually started with the second word
and the first word was already in memo.
@rafaelfranca rafaelfranca merged commit 34df888 into rails:master Mar 13, 2020
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