Class: Aio::Base::Toolkit::Chain

Inherits:
Object
  • Object
show all
Defined in:
lib/aio/base/toolkit/hash.rb

Instance Method Summary collapse

Constructor Details

#initializeChain

Returns a new instance of Chain.



5
6
7
# File 'lib/aio/base/toolkit/hash.rb', line 5

def initialize
  @chain = []
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/aio/base/toolkit/hash.rb', line 28

def empty?
  @chain.empty?
end

#get_lineObject

获取一条链路



24
25
26
# File 'lib/aio/base/toolkit/hash.rb', line 24

def get_line
  @chain.pop
end

#split(key, num) ⇒ Object

分裂出多条key值数组



10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/aio/base/toolkit/hash.rb', line 10

def split(key, num)

  if @chain.empty?
    num.times { @chain.push [key.to_s] }

  else
    last = @chain.pop
    tmp = ::Array.new(num) { last.clone << key }
    @chain.concat tmp
    @chain
  end
end