Project

General

Profile

Actions

Feature #6277

open

Hash#convert_key

Added by trans (Thomas Sawyer) about 12 years ago. Updated over 6 years ago.

Status:
Assigned
Target version:
-
[ruby-core:44270]

Description

=begin
Many times a hash with uniform keys is needed (or is at least preferable) for a particular usecase. To this end I propose ((%Hash#convert_key%)).

h = {}
h.convert_key{ |k| k.to_sym }
h['a'] = 1
h.update('b'=>2)
h #=> {:a=>1, :b=>2}

The idea is similar in concept to ((%#default_proc%)).

Others solutions to fill this need have been tried and used, but almost exclusively are in the form of a new class. Most notable is Rails HashWithIndifferentAccess. But ((%#convert_key%)) has much greater flexibility since keys can be converted to anything.
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0