Class: Array

Inherits:
Object show all
Defined in:
lib/wordnik_ruby_helpers.rb

Instance Method Summary collapse

Instance Method Details

#jiggle(max_deviation = 5) ⇒ Object

Randomly move around the contents of the array, but not by too much.



349
350
351
352
353
# File 'lib/wordnik_ruby_helpers.rb', line 349

def jiggle(max_deviation=5)
  replacement = []
  self.each_slice(max_deviation) {|a| replacement << a.shuffle }
  replacement
end

#remove_blanksObject



334
335
336
# File 'lib/wordnik_ruby_helpers.rb', line 334

def remove_blanks
  self.reject{ |e| e.blank? }
end

#remove_first_elementObject

Like Array.shift, but returns the array instead of removed the element.



339
340
341
# File 'lib/wordnik_ruby_helpers.rb', line 339

def remove_first_element
  self[1..self.size]
end

#remove_last_elementObject

Like Array.pop, but returns the array instead of removed the element.



344
345
346
# File 'lib/wordnik_ruby_helpers.rb', line 344

def remove_last_element
  self[0..self.size-2]
end