What is the syntax for sorting an array alphabetically by the key of a hash or by a string? I would like to sort the following:
['bob', 'apple', 'sandwich', {'lasagne' => 'munch'}, 'tangoed']
to give the following:
['apple', 'bob', {'lasagne' => 'munch'}, 'sandwich', 'tangoed']
Not clear what to do when a hash includes more than one key. Considering always the first key in a hash:
['bob', 'apple', 'sandwich', {'lasagne' => 'munch'}, 'tangoed']
.sort_by{|e| [*e].flatten.first}
#=> ["apple", "bob", {"lasagne"=>"munch"}, "sandwich", "tangoed"]