<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: numbers code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 25 Jul 2008 08:10:37 GMT</pubDate>
    <description>DZone Snippets: numbers code</description>
    <item>
      <title>Ordinals for All Numeric Types</title>
      <link>http://snippets.dzone.com/posts/show/2368</link>
      <description>This snippet will extend all numerical types with a method for returning the English ordinal, i.e. 1st, 2nd, 3rd, 4th, etc.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;class Numeric&lt;br /&gt;  def ordinal&lt;br /&gt;    cardinal = self.to_i.abs&lt;br /&gt;    if (10...20).include?(cardinal) then&lt;br /&gt;      cardinal.to_s &lt;&lt; 'th'&lt;br /&gt;    else&lt;br /&gt;      cardinal.to_s &lt;&lt; %w{th st nd rd th th th th th th}[cardinal % 10]&lt;br /&gt;    end&lt;br /&gt;  end&lt;br /&gt;end&lt;br /&gt; &lt;br /&gt;[1, 22, 123, 10, -3.1415].collect { |i| i.ordinal }&lt;br /&gt;=&gt; ["1st", "22nd", "123rd", "10th", "3rd"]&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License.</description>
      <pubDate>Fri, 04 Aug 2006 22:46:04 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2368</guid>
      <author>jswizard (JavaScript Wizard)</author>
    </item>
  </channel>
</rss>
