LoginSignup
0
1

More than 1 year has passed since last update.

変数hashを作成するためのコード

Posted at

初心に返り復習、備忘としてアウトプットします!

問題
# 下記のメソッドを実行した時に実行結果のように表示されるような変数hashを作成せよ。
puts puts hash.keys
puts hash.values

# 実行結果
one
two
three
1
2
3
解答
# 自身の解答
- hash{"one":1, "two":2, "three":3}
# 模範解答
+ hash = { one: 1, two: 2, three: 3 }

あーやってしまってる。。
=忘れてる。。。

ダブルクォーテーションは文字列に使用しているのであっても実行結果は同じに。

実行結果
irb(main):009:0> hash={"one":1, "two":2, "three":3}
=> {:one=>1, :two=>2, :three=>3}
irb(main):010:0>  puts hash.keys
one
two
three
=> nil
irb(main):011:0> puts hash.values
1
2
3
=> nil

このレベルのものは間違えないようにしていきたいところ!!
頑張れ自分!!

0
1
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
1