Class: Hash

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

Overview

Copyright 2010-2013 Tasos Laskos <[email protected]>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Direct Known Subclasses

Arachni::Component::Manager

Instance Method Summary collapse

Instance Method Details

#downcaseHash



53
54
55
56
57
58
59
60
# File 'lib/arachni/ruby/hash.rb', line 53

def downcase
    stringify_keys.inject({}) do |h, (k, v)|
        k = k.downcase if k.is_a?( String )
        v = v.downcase if v.is_a?( String )
        h[k] = v
        h
    end
end

#stringify_keys(recursively = true) ⇒ Hash

Converts the hash keys to strings.



27
28
29
30
31
32
33
# File 'lib/arachni/ruby/hash.rb', line 27

def stringify_keys( recursively = true )
    stringified = {}
    each do |k, v|
        stringified[k.to_s] = (recursively && v.is_a?( Hash ) ? v.stringify_keys : v)
    end
    stringified
end

#symbolize_keys(recursively = true) ⇒ Hash

Converts the hash keys to symbols.



43
44
45
46
47
48
49
# File 'lib/arachni/ruby/hash.rb', line 43

def symbolize_keys( recursively = true )
    symbolize = {}
    each do |k, v|
        symbolize[k.to_s.to_sym] = (recursively && v.is_a?( Hash ) ? v.symbolize_keys : v)
    end
    symbolize
end