5分で学ぶYAML
「YamlInFiveMinutes」の要約。
配列
↓配列は以下のように記述。
- Memoirs Found in a Bathtub - Snow Crash - Ghost World
print $book_list[0];
で、
Memoirs Found in a Bathtub
が出力。
文書の区切り
---
は、文書の始まりを意味する。
--- - Harry Potter and the Prisoner of Azkaban - Harry Potter and the Goblet of Fire - Harry Potter and the Order of the Phoenix --- - Memoirs Found in a Bathtub - Snow Crash - Ghost World
Hash
↓HashMapは以下のように記述
Stanislaw Lem: Memoirs Found in a Bathtub Neal Stephenson: Snowcrash Daniel Clowes: Ghost World
print $books_by_author['Daniel Clowes'];
で、
Ghost World
が出力。
ネスト
↓要素がHashMapである配列
--- - Stanislaw Lem: Memoirs Found in a Bathtub - Neal Stephenson: Snowcrash - Daniel Clowes: Ghost World
↓HashMapのネスト
--- date: 2003-07-25 letters to: "Hank Bros.: the Car Wash!": 1 Jim O'Connor: 2 Myself: 2
print $mailbox['letters to']['Myself'];
で、
2
が出力。
ブロック
長いテキストを扱う場合に便利なのか。
↓”>”でブロックを開始
--- Concerning Car Washes: > We are sorry to have misplaced this letter. We were told by a reliable source that you were the owner of "Hank Bros.: the Car Wash!". Sorry.
↑上の例は、1つの改行で分けられた2行だと解釈される。
↓”|”でリテラルブロックを開始
Concerning "Jim O'Connor": | You are receiving Jim O'Connor's mail for several reasons: - The nameplate on your mailbox still says his name. - He has told our postman that you screen his mail. - He is living in your ceiling. - He held a raygun to the postman's head.
↑上の例は、5行(空白行入れたら6行)だと解釈される。
インラインな書き方
--- name: Dirk Hockeybranch minutes spent: - 1.02 - 1.34 - 0.7 - 0.89 - 0.94
これは、
--- name: Dirk Hockeybranch minutes spent: [1.02, 1.34, 0.7, 0.89, 0.94]
こう書ける。
HashMapも
---
minutes spent: {one: 1.02, two: 1.34, three: 0.7,
four: 0.89, five: 0.94}
みたいにして書ける。



