Project

General

Profile

Actions

Feature #6079

closed

Hash#each_sorted

Added by walker (Walter Urbaniak) about 12 years ago. Updated about 12 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
[ruby-core:42870]

Description

I often use my own mixin'd Hash#each_sorted that sorts the hash keys and then calls the block with the key and value. It would be useful to be added to Hash. (If this is already in Hash or Enumerable, I didn't see it.)

class Hash
def each_sorted(&block) # sort by key
self.keys.sort.each {|key| block.call(key, self[key])}
end
end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0