Created
August 23, 2015 23:12
-
-
Save eternal44/d939bc732bd98f4fd67e to your computer and use it in GitHub Desktop.
Refactor challenge to use correct input & output layout
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# prints line numbers before each line & aligns the ":" | |
class ListGenerator | |
def column_alignment(lines) | |
lines = lines.split("\n") | |
lines.map.with_index(1) do |output, line_number| | |
"Line #{number_spacing(lines, line_number)}#{line_number}: "\ | |
"#{output}" | |
end | |
end | |
private | |
def number_spacing(lines, line_number) | |
max_line_digits = lines.count.to_s.size | |
" " * (max_line_digits - line_number.to_s.size) | |
end | |
end | |
if __FILE__ == $PROGRAM_NAME | |
lines = "I think the challenge states to split a string. Which may | |
be programmers speech, but should probably have been presented as | |
split a text. | |
So you would be missing a step here, I think. | |
Your names are right for the code, I think. But that is because you | |
read into being handed a string. | |
Think about wanting to present a book with numbered lines. | |
When I pulled your repository and ran the program, it looks like a list of words, rather than a line." | |
puts ListGenerator.new().column_alignment(lines) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment