Last active
December 12, 2015 07:28
-
-
Save blairanderson/4736331 to your computer and use it in GitHub Desktop.
Before and After!
This file contains 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
#------------------BEFORE---------------------------- | |
def width #column width for 'queue print' | |
first_name_length = [12] | |
last_name_length = [12] | |
email_length = [] | |
city_length = [] | |
street_length = [] | |
@queue.each do |person| | |
first_name_length << person[:first_name].length | |
last_name_length << person[:last_name].length | |
email_length << person[:email].length | |
city_length << person[:city].length | |
street_length << person[:street].length | |
end | |
width = Hash.new(12) | |
width[:first_ljust] = first_name_length.max | |
width[:last_ljust] = last_name_length.max | |
width[:email_ljust] = email_length.max | |
width[:city_ljust] = city_length.max | |
width[:street_ljust] = street_length.max | |
width | |
end | |
#---------------------AFTER---------------------------- | |
def width | |
attributes = [:first_name, :last_name, :email, :city, :street] | |
widths = Hash.new([]) | |
widths[:first_name] = [12] | |
widths[:last_name] = [12] | |
@queue.each do |person| | |
attributes.each do |attribute| | |
widths[attribute] << person[attribute].length | |
end | |
end | |
attributes.each do |attribute| | |
widths[attribute] = widths[attribute].max | |
end | |
widths | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment