------art_96681_5080157.1177366466628
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Here's my attempt if you want to compare:
http://jrduncans.googlecode.com/svn/trunk/highcard/ruby/cards.rb (part of my
implementation of a draw-the-high-card game in several languages as I was
learning: http://jrduncans.googlecode.com/svn/trunk/highcard/)

-Stephen

On 4/23/07, Peter Marsh <evil_grunger / hotmail.com> wrote:
>
> Hi, I'm an utter newbie to Ruby (and OOP!) and I thought I'd share my
> very first project. It's nothing special - just a simple class that
> simulates a deck of cards, but I'd like to get your comments to see if
> there's anything I can do better (enjoy!):
>
> class Deck
>   @@Cards >
> ['Two','Three','Four','Five','Six','Seven','Eight','Nine','Ten','Jack','Queen','King','Ace']
>   @@Suits  'Spades','Hearts','Diamonds','Clubs']
>
>   def  initialize
>     @top_card  1
>     @deck  ]
>     52.times do |card|
>       @deck << card
>     end
>   end
>
>   def draw
>     @top_card  top_card + 1
>     if @top_card < 52
>       @deck[@top_card]
>     else
>       raise 'There are only 52 cards in a deck!'
>     end
>   end
>
>   def shuffle
>     @top_card  1
>     @deck  deck.sort_by {rand}
>   end
>
>   def suit
>     @@Suits[@top_card/13]
>   end
>
>   def face
>    factor  top_card/13
>    index  top_card - 13*factor
>    @@Cards[index]
>   end
>
>   def set_card(card)
>     @top_cardłÓd
>   end
>
> end
>
> --
> Posted via http://www.ruby-forum.com/.
>
>


-- 
Stephen Duncan Jr
www.stephenduncanjr.com

------art_96681_5080157.1177366466628--