Skip to content

Instantly share code, notes, and snippets.

@raul
Created June 3, 2009 01:34
Show Gist options
  • Save raul/122728 to your computer and use it in GitHub Desktop.
Save raul/122728 to your computer and use it in GitHub Desktop.
# arrays can be used as a kind of circular list
a = ['a','b','c']
(1..20).each{ |n| puts a[n%a.size]} # forward
(-10..0).each{ |n| puts a[n%a.size]} # backwards
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment