Class: Array

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

Instance Method Summary (collapse)

Instance Method Details

- (Object) jiggle(max_deviation = 5)

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

- (Object) remove_blanks



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

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

- (Object) remove_first_element

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

- (Object) remove_last_element

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