Class: Shithead::Set
- Inherits:
-
Object
- Object
- Shithead::Set
- Defined in:
- lib/shithead/set.rb
Instance Attribute Summary collapse
-
#cards ⇒ Object
readonly
Returns the value of attribute cards.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #add(card) ⇒ Object
- #delete(card) ⇒ Object
- #empty? ⇒ Boolean
-
#initialize(cards = []) ⇒ Set
constructor
A new instance of Set.
- #rank ⇒ Object
- #release_to(object) ⇒ Object
- #size ⇒ Object
- #to_s ⇒ Object
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
#cards ⇒ Object (readonly)
Returns the value of attribute cards.
3 4 5 |
# File 'lib/shithead/set.rb', line 3 def cards @cards end |
#value ⇒ Object (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
17 18 19 |
# File 'lib/shithead/set.rb', line 17 def empty? cards.empty? end |
#rank ⇒ Object
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 |
#size ⇒ Object
30 31 32 |
# File 'lib/shithead/set.rb', line 30 def size cards.length end |
#to_s ⇒ Object
34 35 36 |
# File 'lib/shithead/set.rb', line 34 def to_s cards.collect(&:to_s).join(" ") end |