LoginSignup
4

More than 5 years have passed since last update.

hashのkeyとvalueを逆にして再度hashにする

Last updated at Posted at 2013-07-31

ハッシュのキーと値を逆にして返す

def reverse_hash()
  array = {"kumamoto" => 0, "ooita" => 1, "hukuoka" => 2}
  reverse= [array .values, array .keys].transpose
  hash = Hash[*reverse.flatten]
end

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
4