Created
March 20, 2014 17:10
-
-
Save kazoo04/9668898 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: utf-8 | |
dic = {'朝' => 'first', '昼' => 'second', '夜' => 'third'} | |
# キーから対応する値を取れる | |
# 逆(値からキーを取る)はできない | |
puts dic['朝'] # first | |
puts dic['昼'] # second | |
puts dic['夜'] # third | |
# each を使うとすべてのキーと値の組み合わせを列挙できる | |
# (eachのブロックがキーの数だけ繰り返される) | |
dic.each { |key, value| | |
puts "key = #{key}, value = #{value}" | |
} | |
# キーは1つしかないので上書きされる | |
dic['朝'] = 'fourth' | |
puts dic['朝'] # fourth と出力される |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment