Module: InspectArray

Included in:
DomRender
Defined in:
lib/dom_render.rb

Instance Method Summary collapse

Instance Method Details

#scan(a, i = 0) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/dom_render.rb', line 9

def scan(a, i=0)
  
  if a.first.is_a? Symbol
    
      puts a.inspect    
      
  else
    
    puts ('  ' * i) + '['

    a.each.with_index do |row, j|

      if row.is_a? String or row.is_a? Symbol then
        print ('  ' * (i+1)) + row.inspect
        print ',' unless a.length - 1 == j
        puts
      elsif row.first.is_a? Symbol or row.first.is_a? String
        puts ('  ' * (i+1)) + '['
        puts ('  ' * (i+2)) + row.inspect[1..-2]
        print ('  ' * (i+1)) + ']'
        print ',' unless a.length - 1 == j
        puts
      else
        scan(row,i+1)
        print ',' unless a.length - 1 == j
        puts
      end
    end

    print indent = ('  ' * i) + ']'
  end
end