Class: Array
- Inherits:
- 
      Object
      
        - Object
- Array
 
- Defined in:
- lib/basset/core_extensions.rb
Overview
Extensions to the array class.
Instance Method Summary collapse
- 
  
    
      #pick_random  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns a random item from the array. 
- 
  
    
      #randomize  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns a randomized array. 
- 
  
    
      #randomize!  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Randomizes array in place. 
- 
  
    
      #rest  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns a new array that contains everything except the first element of this one. 
- 
  
    
      #second  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Returns the second item in the array. 
- #sum ⇒ Object
Instance Method Details
#pick_random ⇒ Object
Returns a random item from the array
| 19 20 21 | # File 'lib/basset/core_extensions.rb', line 19 def pick_random self[rand(self.size)] end | 
#randomize ⇒ Object
Returns a randomized array
| 24 25 26 | # File 'lib/basset/core_extensions.rb', line 24 def randomize self.sort_by { rand } end | 
#randomize! ⇒ Object
Randomizes array in place
| 33 34 35 | # File 'lib/basset/core_extensions.rb', line 33 def randomize! self.replace(self.randomize) end | 
#rest ⇒ Object
Returns a new array that contains everything except the first element of this one. (just like in lisp)
| 9 10 11 | # File 'lib/basset/core_extensions.rb', line 9 def rest self.slice(1, size) end | 
#second ⇒ Object
Returns the second item in the array
| 14 15 16 | # File 'lib/basset/core_extensions.rb', line 14 def second self[1] end | 
#sum ⇒ Object
| 28 29 30 | # File 'lib/basset/core_extensions.rb', line 28 def sum inject(0) { |sum, val| sum + val } end |