Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/splib/Array.rb
Instance Method Summary collapse
-
#fixed_flatten(level = -1)) ⇒ Object
1.9 compatible flatten method that allows a level parameter.
Instance Method Details
#fixed_flatten(level = -1)) ⇒ Object
1.9 compatible flatten method that allows a level parameter
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/splib/Array.rb', line 8 def fixed_flatten(level = -1) arr = self case when level < 0 arr.flatten! when level == 0 self when level > 0 arr = [] curr = self level.times do curr.each do |elm| if(elm.respond_to?(:to_ary)) elm.each{|e| arr << e } else arr << elm end end curr = arr.dup end end arr end |