Skip to content
Why walk when you can cycle
Find file
Pull request Compare This branch is 9 commits behind sleepingstu:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


A convenience gem for cycling through a set of values, ported from the 'cycle' functionality found in Rails. It is independent of which framework you use so will run in Sinatra, Padrino or straight up Ruby itself.


gem install bicycle

In a Gemfile:

gem 'bicycle'


Add the following to your app.rb file:

include Bicycle

To use, call the cycle function with a set of values you wish to cycle through.

<%= cycle("odd", "even") %>

For example:

<% @items.each do |item| %>
  <tr class="<%= cycle("odd", "even") %>">
<% end %>

If you want to call multiple instances of the cycle function, you can by specifying a name attribute, like so: '

<%= cycle("red", "green", "blue", :name => "colours") %>

You can also reset a given cycle by calling:

<% reset_cycle("colours") %>

For example:

<% @items.each do |item| %>
  <tr class="<%= cycle("odd", "even", :name => "row_class") -%>">
      <% item.values.each do |value| %>
        <%# Create a named cycle "colors" %>
        <span style="color:<%= cycle("red", "green", "blue", :name => "colors") -%>">
        <%= value %>
      <% end %>
      <% reset_cycle("colors") %>
<% end %>

Contributing to bicycle

  • Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
  • Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
  • Fork the project.
  • Start a feature/bugfix branch.
  • Commit and push until you are happy with your contribution.
  • Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
  • Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.


Copyright (c) 2012 Stuart Chinery and Dave Hrycyszyn, See LICENSE.txt for further details.

Something went wrong with that request. Please try again.