9
9

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

YAMLにおけるネスト

配列だけ,ハッシュだけだとどうしても扱いきれない,または扱いにくいデータがあったりする.
というわけで,配列,ハッシュを互いにネストすることは度々あるが,今回はYAMLでのネストを調べてみた.

配列の中にハッシュをネストする

- name:Matt
  part:vocal&guitar
- name:Padget
  part:guitar
- name:Jay
  part:bass&vocal
- name:Moose
  part:drums

実行結果

=>[{"name"=>"Matt", "part"=>"vocal&guitar"},
   {"name"=>"Padge", "part"=>"guitar"},
   {"name"=>"Jay", "part"=>"bass&vocal"},
   {"name"=>"Moose", "part"=>"drums"}]

ハッシュの中に配列をネストする

name:
  - Matt
  - Padge
  - Jay
  - Moose
part:
  - vocal&guitar
  - guitar
  - bass&vocal
  - drums

実行結果

=>{"name"=>["Matt", "Padge", "Jay", "Moose"],
   "part"=>["vocal&guitar", "guitar", "bass&vocal", "drums]}
9
9
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
9
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?