test for even and odd numbers
if( x%2 == 0) { print "even number" } elsif( x%2 > 0) { print "odd number" }
11307 users tagging and storing useful source code snippets
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
if( x%2 == 0) { print "even number" } elsif( x%2 > 0) { print "odd number" }
# Determines the CSS class based on either the count given # (returns 'even' or 'odd' as the CSS class name) or the class # given (returns the string version of the class, lowercased, # as the CSS class name) def classify( count_or_class, include_class_text = true ) if count_or_class.class == Fixnum value = ( count_or_class % 2 == 0 ? 'even' : 'odd' ) else value = count_or_class.to_s.downcase end if include_class_text 'class="' << value << '"' else value end end
<table> <% count = 0 %> <% @collection.each do |value| %> <tr <%= classify( count ) %>> <td><%=h value %></td> </tr> <% count += 1 %> <% end %> </table>
<tr> <% @columns.each do |column| %> <% data = row.send( column.name ) %> <td <%= classify( data.class ) %>> <%=h data %> </td> <% end %> </tr>