Over the years, through bouncing off various languages, I've come to use this sort of layout:
ATTRIBUTES = %w(
archive_url assignees_url
blobs_url branches_url
collaborators_url comments_url commits_url compare_url
contents_url contributors_url
description downloads_url
events_url
fork forks_url full_name
git_commits_url git_refs_url git_tags_url
hooks_url html_url
id issue_comment_url issue_events_url issues_url
keys_url
languages_url
merges_url milestones_url
name
owner
private pulls_url
stargazers_url statuses_url subscribers_url
subscription_url
tags_url teams_url trees_url
url
)
%w(
description
fork full_name
html_url
login
name
owner
private
url
).each { |a| attr_accessor a.to_sym }
Lines are sorted alphabetically, and each individual word on the line is sorted alphabetically.
If a particular line gets too long I'll wrap it and add blank lines before and after them to delimit them visually, maintaining the sort of the lines and the words in the line.
Most editors make it easy to sort, and it's the first pass cleaning up a messy list that is a pain, afterwards it's no big deal to keep it maintained. I use vim, which has the sort
command, but Sublime Text 2, which I treat as my "notepad" replacement also does it.
I do this for maintenance. I find it a lot easier to scan through a line that's sorted, even if it's not evenly spaced in columns with the other lines, than I do trying to find something that isn't in a sorted order displayed in nice 'n neat columns. Neatness counts but order keeps my head from hurting. Trying to edit a table that is in columns and having it go all to heck because I added a word gets old very quickly, so the columns got tossed out, and I just sort. I'm sure it annoys my co-workers at first when I tell them to do it this way, but they see the benefit soon enough, and it shuts me up. :-)
With Ruby v2.0's addition of %i
, the second example can be changed to:
%i(
description
fork full_name
html_url
login
name
owner
private
url
).each { |s| attr_accessor s }
It's not a big change, but it's a tiny bit cleaner.