Class: Card

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/deck/card.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(rank = 'Joker', suit = 'None') ⇒ Card

Returns a new instance of Card.



9
10
11
12
# File 'lib/deck/card.rb', line 9

def initialize(rank = 'Joker', suit = 'None')
  @suit = suit
  @rank = rank
end

Instance Attribute Details

#rankObject (readonly)

Returns the value of attribute rank.



7
8
9
# File 'lib/deck/card.rb', line 7

def rank
  @rank
end

#suitObject (readonly)

Returns the value of attribute suit.



7
8
9
# File 'lib/deck/card.rb', line 7

def suit
  @suit
end

Instance Method Details

#<(other) ⇒ Object



46
47
48
# File 'lib/deck/card.rb', line 46

def <(other)
  to_i<other.to_i
end

#<=>(other) ⇒ Object



42
43
44
# File 'lib/deck/card.rb', line 42

def <=>(other)
  to_i<=>other.to_i
end

#==(other) ⇒ Object



38
39
40
# File 'lib/deck/card.rb', line 38

def ==(other)
  to_i == other.to_i && suit == other.suit
end

#>(other) ⇒ Object



50
51
52
# File 'lib/deck/card.rb', line 50

def >(other)
  to_i>other.to_i
end

#eachObject



54
55
56
# File 'lib/deck/card.rb', line 54

def each
  yield
end

#inspectObject



26
27
28
# File 'lib/deck/card.rb', line 26

def inspect
  to_s
end

#to_iObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/deck/card.rb', line 58

def to_i
  case @rank.to_s.upcase[0..1]      
    when 'JA'
      11
    when 'QU' 
      12
    when 'KI' 
      13
    when 'AC' 
      14
    when 'JO' 
      15
    else @rank.to_i  
  end  
end

#to_sObject



34
35
36
# File 'lib/deck/card.rb', line 34

def to_s
  "#{rank} of #{suit}"
end