Skip to content

Instantly share code, notes, and snippets.

@nimamehanian
Created February 21, 2013 02:31
Show Gist options
  • Save nimamehanian/5001510 to your computer and use it in GitHub Desktop.
Save nimamehanian/5001510 to your computer and use it in GitHub Desktop.
Reverse the order of an array's elements, without using Ruby's built-in methods.
class Array
def backwards
length = self.length
i = 1
while i != length
i += 1
value = self.slice!(length - i)
self << value
break if self[length - i] == self[0]
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment