<html><head> <title>Class: Hand</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>Hand </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="#M000009">accept</a>, <a href="#M000010">count</a>, <a href="#M000012">has?</a>, <a href="#M000008">new</a>, <a href="#M000011">remove</a>, <a href="#M000013">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="M000008"> <b>new</b>() </a></td></tr> </table> <div class="description"> <p> -method to add a new empty hand to a player </p> </div> <pre class="source"> <span class="ruby-comment cmt"># File cards.rb, line 21</span> 21: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>;<span class="ruby-ivar">@h</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="M000009"> <b>accept</b>(c;) </a></td></tr> </table> <div class="description"> <p> -method to add a card to a players hand </p> </div> <pre class="source"> <span class="ruby-comment cmt"># File cards.rb, line 23</span> 23: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">accept</span> <span class="ruby-identifier">c</span>;<span class="ruby-ivar">@h</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="M000010"> <b>count</b>() </a></td></tr> </table> <div class="description"> <p> -method to count how many cards are in a hand </p> </div> <pre class="source"> <span class="ruby-comment cmt"># File cards.rb, line 25</span> 25: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">count</span>;<span class="ruby-ivar">@h</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="M000012"> <b>has?</b>(v;) </a></td></tr> </table> <div class="description"> <p> -method that returns true if the hand contains one or more cards of a given value -method that returns true if the hand contains one or more cards of a given suit </p> </div> <pre class="source"> <span class="ruby-comment cmt"># File cards.rb, line 30</span> 30: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">has?</span> <span class="ruby-identifier">v</span>;<span class="ruby-ivar">@h</span>.<span class="ruby-identifier">detect</span>{<span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">|</span><span class="ruby-identifier">c</span><span class="ruby-operator">=~</span><span class="ruby-node">/#{v}/</span>};<span class="ruby-keyword kw">end</span> </pre> <table width="100%" cellspacing = 0 cellpadding=5 border=0> <tr><td class="methodtitle"> <a name="M000011"> <b>remove</b>(c;) </a></td></tr> </table> <div class="description"> <p> -method to remove a particular card from a hand. </p> </div> <pre class="source"> <span class="ruby-comment cmt"># File cards.rb, line 27</span> 27: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">remove</span> <span class="ruby-identifier">c</span>;<span class="ruby-ivar">@h</span>.<span class="ruby-identifier">delete</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="M000013"> <b>values</b>() </a></td></tr> </table> <div class="description"> <p> -method to return values of the cards in a hand ( H6, C3, SK, etc ) </p> </div> <pre class="source"> <span class="ruby-comment cmt"># File cards.rb, line 32</span> 32: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">values</span>;<span class="ruby-ivar">@h</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>