Class: Array
Instance Method Summary collapse
-
#jiggle(max_deviation = 5) ⇒ Object
Randomly move around the contents of the array, but not by too much.
- #remove_blanks ⇒ Object
-
#remove_first_element ⇒ Object
Like Array.shift, but returns the array instead of removed the element.
-
#remove_last_element ⇒ Object
Like Array.pop, but returns the array instead of removed the element.
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_blanks ⇒ Object
334 335 336 |
# File 'lib/wordnik_ruby_helpers.rb', line 334 def remove_blanks self.reject{ |e| e.blank? } end |
#remove_first_element ⇒ Object
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_element ⇒ Object
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 |