Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/arrayclass.rb
Instance Method Summary collapse
-
#flatten ⇒ Object
tmp_verb = $VERBOSE $VERBOSE = nil WARNING! Array#flatten is redefined so that it calls the is_a? method (instead of doing it internally as defined in the C code).
-
#flatten! ⇒ Object
WARNING! Array#flatten! is redefined flatten method discussed above.
Instance Method Details
#flatten ⇒ Object
tmp_verb = $VERBOSE $VERBOSE = nil WARNING! Array#flatten is redefined so that it calls the is_a? method (instead of doing it internally as defined in the C code). This allows Arrayclass derived objects to resist flattening by declaring that they are not Arrays. This may be slightly slower than the original, but in all other respects should be the same (i.e., will flatten array derived classes).
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/arrayclass.rb', line 14 def flatten new_array = [] self.each do |v| if v.is_a?(Array) new_array.push( *(v.flatten) ) else new_array << v end end new_array end |
#flatten! ⇒ Object
WARNING! Array#flatten! is redefined flatten method discussed above.
27 28 29 |
# File 'lib/arrayclass.rb', line 27 def flatten! self.replace(flatten) end |