Created
March 15, 2010 18:20
-
-
Save lukeredpath/333128 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Array | |
| def rotate(number_of_times = 1) | |
| returning(self) do | |
| number_of_times.times { unshift(pop) } | |
| end | |
| end | |
| end | |
| # why would you use this? | |
| # | |
| # an array representing the hours in the day, in sequence up to the last hour: | |
| # | |
| # hours_in_day = (0..23).to_a | |
| # hours_up_to_last = hours_in_day.rotate(24 - Time.now.hour) | |
| # | |
| # # assuming its currently 6:30pm | |
| # # => [18, 19, 20, 21, 22, 23, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment