Module: Aio::Base::Toolkit::Hash

Defined in:
lib/aio/base/toolkit/hash.rb

Overview

将嵌套的Hash变成二元数组

Defined Under Namespace

Classes: StringConcat

Class Method Summary collapse

Class Method Details

.flat(cm, chain, res, cm_type) ⇒ Object

返回的是以StringConcat为元素的数组



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/aio/base/toolkit/hash.rb', line 44

def self.flat(cm, chain, res, cm_type)
  cm.each_pair do |key, val|

    if val.kind_of? ::Hash
      chain.split(key, val.size)
      Aio::Base::Toolkit::Hash.flat(val, chain, res, cm_type)

    else

      last_chain = chain.get_line unless chain.empty?
      last_chain ||= []

      last_chain.push(key.to_s)
      last_chain.push(val)

      res << StringConcat.new(last_chain, cm_type)
    end
  end
end

.flat_cm1(cm, chain, res) ⇒ Object



35
36
37
# File 'lib/aio/base/toolkit/hash.rb', line 35

def self.flat_cm1(cm, chain, res)
  Hash.flat(cm, chain, res, :cm1)
end

.flat_cm2(cm, chain, res) ⇒ Object



39
40
41
# File 'lib/aio/base/toolkit/hash.rb', line 39

def self.flat_cm2(cm, chain, res)
  Hash.flat(cm, chain, res, :cm2)
end