class Shithead::SortedStack
Public Instance Methods
add(card)
click to toggle source
# File lib/shithead/sorted_stack.rb, line 2 def add(card) if set_for(card.value) set_for(card.value).add card else sets << Shithead::Set.new([card]) sets.replace sets.sort_by(&:rank).reverse end end
delete(card)
click to toggle source
# File lib/shithead/sorted_stack.rb, line 11 def delete(card) set = set_for(card.value) set.delete card sets.delete set if set.empty? end
take(set)
click to toggle source
# File lib/shithead/sorted_stack.rb, line 18 def take(set) sets.delete set set end
to_s()
click to toggle source
# File lib/shithead/sorted_stack.rb, line 23 def to_s sets.collect(&:to_s).join(" ") end
Private Instance Methods
set_for(value)
click to toggle source
# File lib/shithead/sorted_stack.rb, line 29 def set_for(value) sets.detect { |set| set.value == value } end