Skip to content

Instantly share code, notes, and snippets.

@ahoward
Created May 8, 2012 16:06
Show Gist options
  • Save ahoward/2636753 to your computer and use it in GitHub Desktop.
Save ahoward/2636753 to your computer and use it in GitHub Desktop.
did i mention style is everything?
#
# perl got some things right. here-docs were one of them. YAML takes this
# further when we have to define large data structures.
#
# if you find yourself typing " ' ) ( [ ] too many times in a row, whack
# yourself on the wee-wee with a keyboard and whip out the YAML
#
this_fucking_licks_hairy_balls_to_edit =
[{"name"=>"Ara T. Howard", "email"=>"[email protected]"},
{"name"=>"Ryan Cook", "email"=>"[email protected]"},
{"name"=>"Garett Shulman", "email"=>"[email protected]"}]
and_this_does_not =
YAML.parse '
-
name : Ara T. Howard
email : [email protected]
-
name : Ryan Cook
email : [email protected]
-
name : Garett Shulman
email : [email protected]
'
@geeksam
Copy link

geeksam commented May 8, 2012

Given that there are some really weird fetishes out there, I'm almost certain that someone out there actually enjoys licking hairy balls. But I appreciate the sentiment. (=

@ahoward
Copy link
Author

ahoward commented May 8, 2012

@geeksam - touché

@Telmo
Copy link

Telmo commented May 9, 2012

replacing the typing of " ' ) ( [ ] for the hellish editing of YAML and all its white spaces glory doesn't seem like a good trade off.

@ahoward
Copy link
Author

ahoward commented May 9, 2012

@Telmo - whitespace is hell. but giant structures, as you might put into mongo, require something else.

@TwP
Copy link

TwP commented May 14, 2012

My favored approach

[ {
  "name"  => "Ara T. Howard",
  "email" => "[email protected]"
}, {
  "name"  => "Ryan Cook",
  "email" => "[email protected]"
}, {
  "name"  => "Garett Shulman",
  "email" => "[email protected]"
} ]

I like this because it is pure ruby, and it closely resembles JSON (which is parseable enough by humans).

@ahoward
Copy link
Author

ahoward commented May 14, 2012

moving the code lines separate from the delims is nice for editing....

@geeksam
Copy link

geeksam commented May 14, 2012

I tend to separate the delimiters even more, but that's probably just because TextMate's native indentation support isn't as robust as I wish it were.

I also tend to add a trailing comma after all hash or array entries, even the last one (Some of my coworkers took to calling it "the Livingston-Gray comma"). I like to reorder large hashes to group related keys together, and it sucks to wait 10 seconds for Rails to load and then get hit with a syntax error because I moved the last item up and forgot to add the comma. ;>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment