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.



310
311
312
313
314
# File 'lib/wordnik_ruby_helpers.rb', line 310

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

#remove_blanksObject



295
296
297
# File 'lib/wordnik_ruby_helpers.rb', line 295

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

#remove_first_elementObject

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



300
301
302
# File 'lib/wordnik_ruby_helpers.rb', line 300

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

#remove_last_elementObject

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



305
306
307
# File 'lib/wordnik_ruby_helpers.rb', line 305

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