Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
ルビーが1対1の対応を持っていると仮定すると、ルビーハッシュの関連付けを逆にする組み込みの方法はありますか? キーを明示的にループせずにこれを行うことをお勧めします。
たとえば、私が持っているとします:
a = {1 => "Foo", 2 => "Bar"} a.reverse_association a # ---> {"Foo" => 1, "Bar" => 2}