8
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Yamlの基本

Posted at

配列

- yamada
- sato
- tanaka
[yamada, sato, tanaka]
- yamada
- sato
  - taro
  - jiro
- tanaka

ハッシュ

name: yamada
age: 31
{name: yamada, age: 31}
name: yamada
score:
  math: 70
  english: 69	

配列のハッシュ

name: [yamada, sato]
age: [20, 30]

ハッシュの配列

- {name: yamada, age: 20}
- {name: sato, age: 30}

アンカーとエイリアス

- &designer yamada
- *designer
  • &で定義(アンカー)
  • *で使用(エイリアス)

ハッシュに使用する

- &yamada
  name: yamada
  age: 30
- &sato
  name: sato
  age: 25
  friends:
    - *yamada
- &tanaka
  name: tanaka
  age: 42
  friends:
    - *yamada
    - *sato

ハッシュにエイリアスをつけてマージする

dbuserにエイリアスをつけて、各環境のハッシュにマージする。

dbuser: &dbuser
  user: dbuser
  password: dbpass

development:
  database: myapp_dev
  <<: *dbuser

production:
  database: myapp_production
  <<: *dbuser

test:
  database: myapp_test
  <<: *dbuser

複数の値

  • ハイフンとドットで囲む
---
- hoge
- huga
- piyo
...
---
- foo
- bar
...
8
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?