0
0

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 1 year has passed since last update.

100日後くらいに個人開発するぞ!day045

Posted at

今日は総合問題を解いてみた!

image.png

image.png

今日の備忘録

ハッシュが値の配列でeachを使う場合

  • ハッシュが値の配列でeachを使うと指定した変数にハッシュ要素が順番に代入される
    • 例:usersをuserに代入してnameキーのみ出力したい場合
      • users=[
      • [name:"Yamada",age:21]
      • [name:"Tanaka",age:24]
      • ]
      • users.each do |user|
      • puts user[:name]

nilを利用したif文

  • ifの条件文で指定した値がない場合はnilになるため、else側の処理が実行される
    • 例:userの年齢情報がない場合に「〜さんの年齢は秘密です」と出力したい場合
      • user=[name:"Yamada"]
      • if user[:age]
      • puts "#[user[:name]さんは#[user[:age]]歳です"
      • else
      • puts "#[user[:name]さんの年齢は秘密です"
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?