Skip to content

Instantly share code, notes, and snippets.

@igaiga
Created May 24, 2012 13:57
Show Gist options
  • Save igaiga/2781699 to your computer and use it in GitHub Desktop.
Save igaiga/2781699 to your computer and use it in GitHub Desktop.
Hashの特定条件下でvalueを変える
# -*- 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