Class: Array

Inherits:
Object show all
Defined in:
lib/rant/init.rb

Instance Method Summary collapse

Instance Method Details

#flattenObject


23
24
25
26
27
# File 'lib/rant/init.rb', line 23

def flatten
    cp = self.dup
    cp.flatten!
    cp
end

#flatten!Object


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rant/init.rb', line 28

def flatten!
    res = []
    flattened = false
    self.each { |e|
        if e.respond_to? :to_ary
            res.concat(e.to_ary)
            flattened = true
        else
            res << e
        end
    }
    if flattened
        replace(res)
        flatten!
        self
    end
end