Sha256: 92b2b50d1fa8ff2737857442c74bb6c0cf6b7904f9883980cbe6357b5e62cffa

Contents?: true

Size: 781 Bytes

Versions: 22

Compression:

Stored size: 781 Bytes

Contents

#-------------------------------------------------------------------------------
# Hash data type alterations

class Hash
  def search(search_key, options = {})
    config = Nucleon::Config.ensure(options)
    value  = nil
    
    recurse       = config.get(:recurse, false)
    recurse_level = config.get(:recurse_level, -1)
        
    self.each do |key, data|
      if key == search_key
        value = data
        
      elsif data.is_a?(Hash) && 
        recurse && (recurse_level == -1 || recurse_level > 0)
        
        recurse_level -= 1 unless recurse_level == -1
        value = value.search(search_key, 
          Nucleon::Config.new(config).set(:recurse_level, recurse_level)
        )
      end
      break unless value.nil?
    end
    return value
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
nucleon-0.2.2 lib/core/mod/hash.rb
nucleon-0.2.1 lib/core/mod/hash.rb
nucleon-0.2.0 lib/core/mod/hash.rb
nucleon-0.1.19 lib/core/mod/hash.rb
nucleon-0.1.18 lib/core/mod/hash.rb
nucleon-0.1.17 lib/core/mod/hash.rb
nucleon-0.1.16 lib/core/mod/hash.rb
nucleon-0.1.15 lib/core/mod/hash.rb
nucleon-0.1.14 lib/core/mod/hash.rb
nucleon-0.1.13 lib/core/mod/hash.rb
nucleon-0.1.12 lib/core/mod/hash.rb
nucleon-0.1.11 lib/core/mod/hash.rb
nucleon-0.1.10 lib/core/mod/hash.rb
nucleon-0.1.9 lib/core/mod/hash.rb
nucleon-0.1.8 lib/core/mod/hash.rb
nucleon-0.1.7 lib/core/mod/hash.rb
nucleon-0.1.6 lib/core/mod/hash.rb
nucleon-0.1.5 lib/core/mod/hash.rb
nucleon-0.1.4 lib/core/mod/hash.rb
nucleon-0.1.3 lib/core/mod/hash.rb