Created
May 24, 2012 13:57
-
-
Save igaiga/2781699 to your computer and use it in GitHub Desktop.
Hashの特定条件下でvalueを変える
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
# -*- coding: utf-8 -*- | |
# Hash のキーの中に a という文字が含まれるときに、そのバリューを大文字に変換したHashを作るコードを書いてください。 | |
# {:alice=>"year!", :bob=>"yo!", :linda => "wow!" } | |
# {:alice=>"YEAR!", :bob=>"yo!", :linda => "WOW!" } | |
h = {:alice=>"year!", :bob=>"yo!", :linda => "wow!" } | |
h.each do |key, value| | |
h[key] = value.upcase if key =~ /a/ | |
end | |
p h |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment