Sort hash by key, return hash in Ruby November 6, 2022 by Tarik In Ruby 2.1 it is simple: h.sort.to_h