<html><head> <title>Class: Deck</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel=StyleSheet href=".././rdoc-style.css" type="text/css" media=screen> <script type="text/javascript" language="JavaScript"> <!-- function popCode(url) { parent.frames.source.location = url } //--> </script> </head> <body bgcolor="white"> <table width="100%" border=0 cellspacing=0> <tr class="title-row"> <td class="big-title-font"> <font size=-3><B>Class</B><BR></font>Deck </td> <td align="right"> <table cellspacing=0 cellpadding=2> <tr valign="top"> <td class="small-title-font">In:</td> <td class="small-title-font"> <a href="../files/cards_rb.html">cards.rb</a> </td> </tr> <tr> <td class="small-title-font">Parent:</td> <td class="small-title-font"> Object </td> </tr> </table> </td> </tr> </table><br> <!-- banner header --> <table width="100%"><tr><td align="center"> <map id="map" name="map"> <area shape="RECT" coords="7,17,79,65" href="Deck.html" alt="Deck "> <area shape="RECT" coords="103,17,175,65" href="Hand.html" alt="Hand "> </map> <img src="../dot/f_1.gif" usemap="#map" border=0 alt="TopLevel"> </td></tr></table> </div> <table cellpadding=5 width="100%"> <tr><td class="tablesubtitle">Methods</td></tr> </table><br> <div class="name-list"> <a href="#M000004">bury</a>, <a href="#M000005">count</a>, <a href="#M000003">draw</a>, <a href="#M000001">new</a>, <a href="#M000006">reset</a>, <a href="#M000002">shuffle</a>, <a href="#M000007">values</a>, </div> <div id="section"> <table cellpadding=5 width="100%"> <tr><td class="tablesubtitle">Public Class methods</td></tr> </table> <table width="100%" cellspacing = 0 cellpadding=5 border=0> <tr><td class="methodtitle"> <a name="M000001"> <b>new</b>() </a></td></tr> </table> <div class="description"> <p> -method for the creation of a deck of 52 cards </p> </div> <pre class="source"> <span class="ruby-comment cmt"># File cards.rb, line 5</span> 5: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>;<span class="ruby-identifier">reset</span>;<span class="ruby-keyword kw">end</span> </pre> <table cellpadding=5 width="100%"> <tr><td class="tablesubtitle">Public Instance methods</td></tr> </table> <table width="100%" cellspacing = 0 cellpadding=5 border=0> <tr><td class="methodtitle"> <a name="M000004"> <b>bury</b>(c;) </a></td></tr> </table> <div class="description"> <p> -method to add a card to the bottom of the deck(the card should not already be in the deck) </p> </div> <pre class="source"> <span class="ruby-comment cmt"># File cards.rb, line 11</span> 11: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">bury</span> <span class="ruby-identifier">c</span>;<span class="ruby-operator">!</span><span class="ruby-ivar">@d</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">c</span>)<span class="ruby-operator">&&</span><span class="ruby-ivar">@d</span>.<span class="ruby-identifier">push</span>(<span class="ruby-identifier">c</span>);<span class="ruby-keyword kw">end</span> </pre> <table width="100%" cellspacing = 0 cellpadding=5 border=0> <tr><td class="methodtitle"> <a name="M000005"> <b>count</b>() </a></td></tr> </table> <div class="description"> <p> -method to return a value with total number of cards in deck </p> </div> <pre class="source"> <span class="ruby-comment cmt"># File cards.rb, line 13</span> 13: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">count</span>;<span class="ruby-ivar">@d</span>.<span class="ruby-identifier">size</span>;<span class="ruby-keyword kw">end</span> </pre> <table width="100%" cellspacing = 0 cellpadding=5 border=0> <tr><td class="methodtitle"> <a name="M000003"> <b>draw</b>() </a></td></tr> </table> <div class="description"> <p> -method to return the top card of a deck and removes it from the deck </p> </div> <pre class="source"> <span class="ruby-comment cmt"># File cards.rb, line 9</span> 9: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">draw</span>;<span class="ruby-ivar">@d</span>.<span class="ruby-identifier">shift</span>;<span class="ruby-keyword kw">end</span> </pre> <table width="100%" cellspacing = 0 cellpadding=5 border=0> <tr><td class="methodtitle"> <a name="M000006"> <b>reset</b>() </a></td></tr> </table> <div class="description"> <p> -method to reset the deck to 52 cards </p> </div> <pre class="source"> <span class="ruby-comment cmt"># File cards.rb, line 15</span> 15: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reset</span>;<span class="ruby-ivar">@d</span>=[];<span class="ruby-constant">Ranks</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span><span class="ruby-constant">Suits</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">j</span><span class="ruby-operator">|</span><span class="ruby-ivar">@d</span>.<span class="ruby-identifier">push</span> <span class="ruby-identifier">i</span><span class="ruby-operator">+</span><span class="ruby-identifier">j</span>}};<span class="ruby-keyword kw">end</span> </pre> <table width="100%" cellspacing = 0 cellpadding=5 border=0> <tr><td class="methodtitle"> <a name="M000002"> <b>shuffle</b>() </a></td></tr> </table> <div class="description"> <p> -method to shuffle a deck of cards </p> </div> <pre class="source"> <span class="ruby-comment cmt"># File cards.rb, line 7</span> 7: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">shuffle</span>;<span class="ruby-identifier">h</span>=[];<span class="ruby-ivar">@d</span>.<span class="ruby-identifier">each</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">crd</span><span class="ruby-operator">|</span><span class="ruby-identifier">h</span>.<span class="ruby-identifier">insert</span>(<span class="ruby-identifier">rand</span>(<span class="ruby-identifier">h</span>.<span class="ruby-identifier">size</span><span class="ruby-operator">+</span><span class="ruby-value">1</span>),<span class="ruby-identifier">crd</span>)};<span class="ruby-ivar">@d</span>=<span class="ruby-identifier">h</span>;<span class="ruby-keyword kw">end</span> </pre> <table width="100%" cellspacing = 0 cellpadding=5 border=0> <tr><td class="methodtitle"> <a name="M000007"> <b>values</b>() </a></td></tr> </table> <div class="description"> <p> -method to return values of the cards in the deck ( H6, C3, SK, etc ) </p> </div> <pre class="source"> <span class="ruby-comment cmt"># File cards.rb, line 17</span> 17: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">values</span>;<span class="ruby-ivar">@d</span>.<span class="ruby-identifier">inject</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">s</span>,<span class="ruby-identifier">c</span><span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator"><<</span><span class="ruby-value str">" "</span><span class="ruby-operator">+</span><span class="ruby-identifier">c</span>};<span class="ruby-keyword kw">end</span> </pre> <!-- method descriptions --> </body> </html>