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:
After the change
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.
Description
This pull request fixes a bug that caused the
print_wrapped
method in theThor::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 thememo
variable.Before the change:
After the change
To see why this occurs you can run the following code on IRB or PRY:
As you can see the first iteration already has
"hello"
inmemo
and the firstword
is actually"word!"
. Theprint_wrapped
was not accounting for this and therefore given the right conditions the method would print beyond the edge of the terminal.