{"id":26201901,"url":"https://github.com/sveredyuk/ruby-circular-array","last_synced_at":"2025-06-15T00:33:39.510Z","repository":{"id":62555674,"uuid":"206550086","full_name":"sveredyuk/ruby-circular-array","owner":"sveredyuk","description":"Endless array for Ruby. Have fun that never ends!","archived":false,"fork":false,"pushed_at":"2022-08-31T10:53:07.000Z","size":20,"stargazers_count":14,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-16T06:11:38.917Z","etag":null,"topics":["arrays","endless","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sveredyuk.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-05T11:42:41.000Z","updated_at":"2023-11-05T20:42:55.000Z","dependencies_parsed_at":"2022-11-03T05:31:07.961Z","dependency_job_id":null,"html_url":"https://github.com/sveredyuk/ruby-circular-array","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/sveredyuk/ruby-circular-array","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sveredyuk%2Fruby-circular-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sveredyuk%2Fruby-circular-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sveredyuk%2Fruby-circular-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sveredyuk%2Fruby-circular-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sveredyuk","download_url":"https://codeload.github.com/sveredyuk/ruby-circular-array/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sveredyuk%2Fruby-circular-array/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259905406,"owners_count":22929916,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arrays","endless","ruby"],"created_at":"2025-03-12T03:24:15.926Z","updated_at":"2025-06-15T00:33:39.473Z","avatar_url":"https://github.com/sveredyuk.png","language":"Ruby","readme":"# CircularArray\n\n[![Build Status](https://travis-ci.com/sveredyuk/ruby-circular-array.svg?branch=master)](https://travis-ci.com/sveredyuk/ruby-circular-array)\n\nYou have a week with days and you want to iterate over the week and never met `nil`, but:\n```ruby\nweek = [:mon, :tue, :wed, :thu, :fri, :sat, :sun]\nweek[0] # =\u003e :mon\nweek[3] # =\u003e :thu\nweek[6] # =\u003e :sun\nweek[7] # =\u003e nil... stop what?! I need monday!\n```\n\nBut it's possible with `CircularArray`\n```ruby\nrequire 'circular_array'\n\ncircular_week = CircularArray[:mon, :tue, :wed, :thu, :fri, :sat, :sun]\n\n# It behaves like Array. Basically it inherits Array:\ncircular_week.kind_of? Array # =\u003e true\n\n# But it is endless:\ncircular_week[0] # =\u003e :mon\ncircular_week[3] # =\u003e :thu\ncircular_week[6] # =\u003e :sun\ncircular_week[7] # =\u003e :mon\ncircular_week[8] # =\u003e :tue\ncircular_week[9] # =\u003e :wed\ncircular_week[10] # =\u003e :thu\ncircular_week[11] # =\u003e :fri\ncircular_week[12] # =\u003e :sat\ncircular_week[13] # =\u003e :sun\ncircular_week[14] # =\u003e :mon\n# great!\n```\n\n**You can use it for recursive matching, but do not forget to add anti-infinity loop clause**\n\nOnly for empty collection in returns `nil`\n```ruby\nempty_circular_array = CircularArray.new([])\nempty_circular_array[1] # =\u003e nil\n```\n\n## Use cases\n\n1. Round-robin selection algorithm\n2. Matching over a list of possible solutions\n3. Cycling dates for complex delivery logic\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'circular_array'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install circular_array\n\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/circular_array. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the CircularArray project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/circular_array/blob/master/CODE_OF_CONDUCT.md).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsveredyuk%2Fruby-circular-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsveredyuk%2Fruby-circular-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsveredyuk%2Fruby-circular-array/lists"}