Skip to content

Instantly share code, notes, and snippets.

@blairanderson
Last active December 12, 2015 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save blairanderson/4736331 to your computer and use it in GitHub Desktop.
Save blairanderson/4736331 to your computer and use it in GitHub Desktop.
Before and After!
#------------------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