Class: Array
Instance Method Summary collapse
Instance Method Details
#flatten ⇒ Object
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 |