Created
February 3, 2011 06:58
-
-
Save tmtk75/809142 to your computer and use it in GitHub Desktop.
YAML showcase
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
### | |
### YAML Showcase | |
### Thanks for http://jp.rubyist.net/magazine/?0009-YAML | |
### To run: | |
### cat $0 | ruby -r pp -r yaml -e 'pp YAML.load STDIN.read' | |
### | |
collection: | |
mapping(block-style): | |
name: Taro | |
age: 32 | |
mapping(flow-style): {name: Jiro, age: 28} | |
mapping(nest): {name: {first: Taro, last: Yamada}, age: 32} | |
sequence(block-style): | |
- 1 | |
- 2 | |
- 3 | |
sequence(flow-style): [1, 2, 3] | |
sequence(nest): | |
- [1, 2] | |
- [3, 4] | |
- | |
- 5 | |
- 6 | |
scalar: | |
decimal: | |
- 123 # | |
- 1,234,567,890 # | |
- 0644 # oct | |
- 0xFF # hex | |
- 0.05 # Maybe, no exponetial notation | |
boolean: [true, yes, on, false, no, off] | |
"null": [~, null] | |
date: 2005-01-01 | |
timestamp: 2005-01-01 00:00:00 +09:00 | |
string: ['true', "2005", hello world] | |
text(keep line-break): | | |
aaa | |
bbb | |
ccc | |
text(keep line-break with the last): |+ | |
aaa | |
bbb | |
ccc | |
text(keep line-break without the last): |- | |
aaa | |
bbb | |
ccc | |
text(replace line-break to space except for the last): > | |
aaa | |
bbb | |
ccc | |
text(replace line-break to space keeping the last): >+ | |
aaa | |
bbb | |
ccc | |
with indent width: |4 # Remove 4 spaces from begin of each line | |
foo | |
bar | |
baz | |
bee | |
anchor and alias (like the pointer notation of C): | |
simple: | |
- &mark 'Hello World' # To put an anchor | |
- *mark | |
- *mark | |
complex: | |
posts: | |
- &ceo {id: 91, name: CEO} | |
- &cfo {id: 92, name: CFO} | |
- &cto {id: 93, name: CTO} | |
employees: | |
- {name: Suzuki, post: *ceo} | |
- {name: Ohta, post: *cfo} | |
- {name: null, post: *cto} | |
... | |
After 3 dots, all is ignored like __END__ of perl. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment