Sha256: 9fcf21fe058b02d862a1ce0c420b4837df9c0d985abdbd6e6da780fd9b400809

Contents?: true

Size: 462 Bytes

Versions: 6

Compression:

Stored size: 462 Bytes

Contents

# encoding: utf-8

class Hash
  # Maps a hash into a hash, whose keys have been replaced with names of the
  # key objects (which are assumed to respond to +#name+ method).
  # 
  def keys_to_names
    with_keys do |key| key.name || key end
  end

  # Modifies a hash in place so that the keys are replaced with key names (key
  # objects are assumed to respond to +#name+ method).
  # 
  def keys_to_names!
    with_keys! do |key| key.name || key end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
y_support-2.1.5 lib/y_support/name_magic/hash.rb
y_support-2.1.4 lib/y_support/name_magic/hash.rb
y_support-2.1.3 lib/y_support/name_magic/hash.rb
y_support-2.1.2 lib/y_support/name_magic/hash.rb
y_support-2.1.1 lib/y_support/name_magic/hash.rb
y_support-2.1.0 lib/y_support/name_magic/hash.rb