Method: Array#flipflop
- Defined in:
- lib/extra_lib/core_ext/array.rb
#flipflop ⇒ Object
Thanks to manveru for this fun code :) All it does is flip the first and last elements. Pretty cool, eh? :)
Example: [1, 2, 3, 4].flipflop #=> [4, 2, 3, 1]
Returns: Array
9 10 11 12 13 14 15 |
# File 'lib/extra_lib/core_ext/array.rb', line 9 def flipflop if size > 1 [last] + self[1...-1] + [first] else self end end |