LoginSignup
0
0

More than 3 years have passed since last update.

Rubyでキーとバリューを書く

Last updated at Posted at 2020-08-01

3種類の参考を元に、keyとvalueの種類について以下にまとめていく。

1. hash1 = {"title" => "天気の子"}

2. hash2 = {:title => "天気の子"}

3. hash3 = {title: => "天気の子"}

hash1は文字列をキーに使っている。

hash2とhash3はシンボルをキーに使っている。

hash2とhash3は同じ内容であるが、hash3が最もシンプルな書き方になる。

ハッシュのキーとして使う場合は、シンボルの方が実行の速度が早いためシンボルの使用が推奨されています。

0
0
2

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