Class: Shithead::Set

Inherits:
Object
  • Object
show all
Defined in:
lib/shithead/set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cards = []) ⇒ Set

Returns a new instance of Set.



5
6
7
# File 'lib/shithead/set.rb', line 5

def initialize(cards = [])
  @cards = cards
end

Instance Attribute Details

#cardsObject (readonly)

Returns the value of attribute cards.



3
4
5
# File 'lib/shithead/set.rb', line 3

def cards
  @cards
end

#valueObject (readonly)

Returns the value of attribute value.



2
3
4
# File 'lib/shithead/set.rb', line 2

def value
  @value
end

Instance Method Details

#add(card) ⇒ Object



9
10
11
# File 'lib/shithead/set.rb', line 9

def add(card)
  cards << card
end

#delete(card) ⇒ Object



13
14
15
# File 'lib/shithead/set.rb', line 13

def delete(card)
  cards.delete card
end

#empty?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/shithead/set.rb', line 17

def empty?
  cards.empty?
end

#rankObject



21
22
23
# File 'lib/shithead/set.rb', line 21

def rank
  cards.first && cards.first.rank
end

#release_to(object) ⇒ Object



25
26
27
28
# File 'lib/shithead/set.rb', line 25

def release_to(object)
  cards.each { |card| object.add card }
  cards.clear
end

#sizeObject



30
31
32
# File 'lib/shithead/set.rb', line 30

def size
  cards.length
end

#to_sObject



34
35
36
# File 'lib/shithead/set.rb', line 34

def to_s
  cards.collect(&:to_s).join(" ")
end