Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/array.rb
Overview
© 2008-01-07 Philipp Hofmann <[email protected]>
Instance Method Summary collapse
Instance Method Details
#add(a) ⇒ Object
8 9 10 11 12 |
# File 'lib/array.rb', line 8 def add(a) n = [] each_index { |i| n << (self[i] + a[i]) } n end |
#add!(a) ⇒ Object
14 15 16 |
# File 'lib/array.rb', line 14 def add!(a) replace(add(a)) end |
#shuffle ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/array.rb', line 18 def shuffle # method 1, sorting is always slower sort_by { rand } # method 2, maybe faster # a = self.clone # a.collect { a.slice!(rand(a.size)) } end |