Sha256: a21a9fd16e3d821fe20bb174da540b433d52b506b01594cd7d8e2b9f26ddf905
Contents?: true
Size: 699 Bytes
Versions: 1
Compression:
Stored size: 699 Bytes
Contents
module CardsLib class Card def initialize(face) raise InvalidCardFace, "face cannot be blank" if face.to_s.empty? @suit = nil @rank = nil if face.is_a? Hash @suit = face.fetch(:suit) { nil } @rank = face.fetch(:rank) { nil } if @rank && @suit str = "" if @rank.length.>(1) && @suit.length.>(1) str = " of " end @face = [@rank, str, @suit].join end else @face = face end end def face @face end def suit @suit || @face[1..-1] end def rank @rank || @face[0] end end class InvalidCardFace < Exception end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cards_lib-0.0.5 | lib/cards_lib/card.rb |