Class: Hash

Inherits:
Object show all
Defined in:
lib/doing/hash.rb

Overview

Hash helpers

Instance Method Summary collapse

Instance Method Details

#cloneObject

#deep_freezeObject

Freeze all values in a hash

Returns:

  • Hash with all values frozen

#deep_freeze!Object

#deep_set(path, value) ⇒ Object

Set a nested hash value using an array

Examples:

{}.deep_set(['one', 'two'], 'value')
# => { 'one' => { 'two' => 'value' } }

Parameters:

  • path (Array)

    key path

  • value

    The value

#deep_thawObject

#deep_thaw!Object

#delete_unless_key(key, to_delete) ⇒ Object

Delete array of keys unless key exists

Parameters:

  • key

    The key to verify

  • to_delete (Array)

    the keys to delete if key doesn't exist

#remove_emptyObject

Remove keys with empty values

#rename_key(old_key, new_key, keep: false) ⇒ Object

Rename a key, deleting old key

Parameters:

  • old_key

    The original key

  • new_key

    The new key

  • keep (Boolean) (defaults to: false)

    if true, keep old key in addition to new key

#rename_keys(*pairs) ⇒ Object

Rename keys in batch

Parameters:

  • pairs (Array)

    pairs of old and new keys

#stringify_keysHash

Turn all keys into string

If the hash has both a string and a symbol for key, keep the string value, discarding the symnbol value

Returns:

  • (Hash)

    a copy of the hash where all its keys are strings

#stringify_valuesHash

Turn all non-numeric values into strings

Returns:

  • (Hash)

    a copy of the hash where all non-numeric values are strings

#symbolize_keysHash

Turn all keys into symbols

If the hash has both a string and a symbol for a key, keep the symbol value and discard the string value

Returns:

  • (Hash)

    a copy of the hash where all its keys are symbols

#tag_filter_to_optionsObject

#to_viewHash

Convert an options hash to a view config

Returns:

  • (Hash)

    View representation of the object.