Skip to content

Instantly share code, notes, and snippets.

@sausheong
Created April 29, 2012 05:20
Show Gist options
  • Save sausheong/2533651 to your computer and use it in GitHub Desktop.
Save sausheong/2533651 to your computer and use it in GitHub Desktop.
Using the circular list
$ irb -r ./circularlist.rb
1.9.3-p125 :001 > cl = CircularList.new %w(a b c d e f g h)
=> ["a", "b", "c", "d", "e", "f", "g", "h"]
1.9.3-p125 :002 > cl.current
=> "a"
1.9.3-p125 :004 > cl.next
=> "b"
1.9.3-p125 :005 > cl.previous
=> "a"
1.9.3-p125 :007 > cl.next 3
=> "d"
1.9.3-p125 :009 > cl.previous 5
=> "g"
1.9.3-p125 :010 >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment