Module: Arrow::HashUtilities

Included in:
Config, Config::ConfigStruct, Template, Template::Parser
Defined in:
lib/arrow/mixins.rb

Overview

A collection of utilities for working with Hashes.

Constant Summary

HashMergeFunction =

Recursive hash-merge function

Proc.new {

Instance Method Summary

Instance Method Details

- (Object) stringify_keys(hash)

Return a version of the given hash with its keys transformed into Strings from whatever they were before.



50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/arrow/mixins.rb', line 50

def stringify_keys( hash )
  newhash = {}

  hash.each do |key,val|
    if val.is_a?( Hash )
      newhash[ key.to_s ] = stringify_keys( val )
    else
      newhash[ key.to_s ] = val
    end
  end

  return newhash
end

- (Object) symbolify_keys(hash) Also known as: internify_keys

Return a duplicate of the given hash with its identifier-like keys transformed into symbols from whatever they were before.



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/arrow/mixins.rb', line 67

def symbolify_keys( hash )
  newhash = {}

  hash.each do |key,val|
    keysym = key.to_s.dup.untaint.to_sym

    if val.is_a?( Hash )
      newhash[ keysym ] = symbolify_keys( val )
    else
      newhash[ keysym ] = val
    end
  end

  return newhash
end