Решение на Четвърта задача от Кристиян Тодоров

Обратно към всички решения

Към профила на Кристиян Тодоров

Резултати

  • 1 точка от тестове
  • 1 отнета точка
  • 0 точки общо
  • 5 успешни тест(а)
  • 52 неуспешни тест(а)

Код

module Rules
def get_rank
all_ranks = {jack: 11, queen: 12, king: 13, ace: 14}
case rank
when 2..10
rank
else
all_ranks[rank]
end
end
def get_suit
all_suits = {spades: 4, hearts: 3, diamonds: 2, clubs: 1}
all_suits[suit]
end
end
module CardGenerator
module_function
@all_ranks = {jack: 11, queen: 12, king: 13, ace: 14}
def generate(first = 2)
clubs(first) + diamonds(first) + hearts(first) + spades(first)
end
def clubs(first)
all_clubs = (first..10).to_a
@all_ranks.keys.each { |rank| all_clubs << rank.to_sym}
generated_clubs = []
all_clubs.each {|club| generated_clubs << Card.new(club, :clubs)}
generated_clubs
end
def diamonds(first)
all_diamonds = (first..10).to_a
@all_ranks.keys.each { |rank| all_diamonds << rank.to_sym.to_sym}
generated_diamonds = []
all_diamonds.each {|club| generated_diamonds << Card.new(club, :diamonds)}
generated_diamonds
end
def hearts(first)
all_hearts = (first..10).to_a
@all_ranks.keys.each { |rank| all_hearts << rank.to_sym}
generated_hearts = []
all_hearts.each {|club| generated_hearts << Card.new(club, :hearts)}
generated_hearts
end
def spades(first)
all_spades = (first..10).to_a
@all_ranks.keys.each { |rank| all_spades << rank.to_sym}
generated_spades = []
all_spades.each {|club| generated_spades << Card.new(club, :spades)}
generated_spades
end
end
class Card
include Rules
@suit
@rank
def initialize(card_rank, card_suit)
@suit = card_suit
@rank = card_rank
end
def rank
@rank
end
def suit
@suit
end
def ==(other_card)
rank == other_card.rank and suit == other_card.suit
end
def to_s
case rank
when 2..10
"#{@rank} of #{@suit.capitalize}"
else
"#{@rank.capitalize} of #{@suit.capitalize}"
end
end
end
class Deck
include Enumerable
include CardGenerator
@deck
def initialize(starting_deck = [])
if starting_deck.empty?
@deck = CardGenerator.generate
else
@deck = starting_deck
end
end
def deck
@deck
end
def size
@deck.length
end
def deal(number_of_cards)
hand = []
shuffle
while number_of_cards > 0 and deck.size > 0
number_of_cards -= 1
hand << draw_top_card
end
Deck.new(hand)
end
def draw_top_card
@deck.delete_at(0)
end
def draw_bottom_card
@deck.delete_at(-1)
end
def top_card
@deck[0]
end
def bottom_card
@deck[-1]
end
def shuffle
@deck.shuffle!
end
def sort
@deck.sort! { |x, y| y.get_rank <=> x.get_rank }
@deck.sort! { |x, y| y.get_suit <=> x.get_suit }
end
def to_s
puts @deck
end
def each
current = 0
while current < deck.length
yield deck[current]
current += 1
end
end
end
class WarDeck < Deck
@war_deck
def initialize(starting_deck = Deck.new)
@war_deck = starting_deck
end
def get_deck
@war_deck.deck
end
def to_s
puts @war_deck.deck
end
def deal
WarDeck.new(@war_deck.deal(26))
end
def play_card
get_deck.delete_at(0)
end
def allow_face_up?
get_deck.length <= 3
end
end

Лог от изпълнението

...FFFFFFFFFFF..FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

Failures:

  1) WarDeck behaves like a deck implements Enumerable
     Failure/Error: expect(small_deck.to_a).to eq [ace_of_spades, nine_of_clubs]
     NoMethodError:
       undefined method `length' for nil:NilClass
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:140
     # /tmp/d20151112-27349-1wz1bad/solution.rb:156:in `each'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:11:in `to_a'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:11:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) WarDeck behaves like a deck fills the deck if no initialize parameters are given
     Failure/Error: expect(deck.to_a).to match_array all_available_cards
     NoMethodError:
       undefined method `length' for nil:NilClass
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:140
     # /tmp/d20151112-27349-1wz1bad/solution.rb:156:in `each'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:18:in `to_a'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:18:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) WarDeck behaves like a deck #size returns the size of the deck
     Failure/Error: expect(small_deck.size).to eq 2
     NoMethodError:
       undefined method `length' for nil:NilClass
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:140
     # /tmp/d20151112-27349-1wz1bad/solution.rb:112:in `size'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:23:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  4) WarDeck behaves like a deck #draw_top_card pops the top-most card
     Failure/Error: expect(small_deck.draw_top_card).to eq ace_of_spades
     NoMethodError:
       undefined method `delete_at' for nil:NilClass
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:140
     # /tmp/d20151112-27349-1wz1bad/solution.rb:126:in `draw_top_card'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:29:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  5) WarDeck behaves like a deck #draw_bottom_card pops the bottom-most card
     Failure/Error: expect(small_deck.draw_bottom_card).to eq nine_of_clubs
     NoMethodError:
       undefined method `delete_at' for nil:NilClass
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:140
     # /tmp/d20151112-27349-1wz1bad/solution.rb:130:in `draw_bottom_card'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:36:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  6) WarDeck behaves like a deck #top peeks at the top-most card
     Failure/Error: expect(small_deck.top_card).to eq ace_of_spades
     NoMethodError:
       undefined method `[]' for nil:NilClass
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:140
     # /tmp/d20151112-27349-1wz1bad/solution.rb:134:in `top_card'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:43:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  7) WarDeck behaves like a deck #bottom peeks at the bottom-most card
     Failure/Error: expect(small_deck.bottom_card).to eq nine_of_clubs
     NoMethodError:
       undefined method `[]' for nil:NilClass
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:140
     # /tmp/d20151112-27349-1wz1bad/solution.rb:138:in `bottom_card'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:50:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  8) WarDeck behaves like a deck #shuffle does not remove cards from the deck
     Failure/Error: initial_size = deck.size
     NoMethodError:
       undefined method `length' for nil:NilClass
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:140
     # /tmp/d20151112-27349-1wz1bad/solution.rb:112:in `size'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:59:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  9) WarDeck behaves like a deck #to_s returns the names of the cards, each on its own line
     Failure/Error: expect(small_deck.to_s.strip).to eq "Ace of Spades\n9 of Clubs"
     NoMethodError:
       undefined method `deck' for #<Array:0x007fef58b26278>
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:140
     # /tmp/d20151112-27349-1wz1bad/solution.rb:175:in `to_s'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:68:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  10) WarDeck #sort sorts the cards in the defined order
     Failure/Error: expect(deck.sort.to_a).to eq [jack_of_spades, ten_of_hearts, ace_of_clubs, two_of_clubs]
     NoMethodError:
       undefined method `sort!' for nil:NilClass
     # /tmp/d20151112-27349-1wz1bad/solution.rb:146:in `sort'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:155:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  11) WarDeck hand #deal deals 26 cards
     Failure/Error: expect(hand.size).to eq 26
     NoMethodError:
       undefined method `length' for nil:NilClass
     # /tmp/d20151112-27349-1wz1bad/solution.rb:112:in `size'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:164:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  12) BeloteDeck behaves like a deck implements Enumerable
     Failure/Error: subject(:deck_class) { Object.const_get(klass) }
     NameError:
       uninitialized constant BeloteDeck
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:191
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `const_get'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:9:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  13) BeloteDeck behaves like a deck fills the deck if no initialize parameters are given
     Failure/Error: subject(:deck_class) { Object.const_get(klass) }
     NameError:
       uninitialized constant BeloteDeck
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:191
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `const_get'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:15:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  14) BeloteDeck behaves like a deck #size returns the size of the deck
     Failure/Error: subject(:deck_class) { Object.const_get(klass) }
     NameError:
       uninitialized constant BeloteDeck
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:191
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `const_get'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:23:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  15) BeloteDeck behaves like a deck #draw_top_card pops the top-most card
     Failure/Error: subject(:deck_class) { Object.const_get(klass) }
     NameError:
       uninitialized constant BeloteDeck
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:191
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `const_get'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:29:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  16) BeloteDeck behaves like a deck #draw_bottom_card pops the bottom-most card
     Failure/Error: subject(:deck_class) { Object.const_get(klass) }
     NameError:
       uninitialized constant BeloteDeck
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:191
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `const_get'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:36:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  17) BeloteDeck behaves like a deck #top peeks at the top-most card
     Failure/Error: subject(:deck_class) { Object.const_get(klass) }
     NameError:
       uninitialized constant BeloteDeck
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:191
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `const_get'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:43:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  18) BeloteDeck behaves like a deck #bottom peeks at the bottom-most card
     Failure/Error: subject(:deck_class) { Object.const_get(klass) }
     NameError:
       uninitialized constant BeloteDeck
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:191
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `const_get'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:50:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  19) BeloteDeck behaves like a deck #shuffle does not remove cards from the deck
     Failure/Error: subject(:deck_class) { Object.const_get(klass) }
     NameError:
       uninitialized constant BeloteDeck
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:191
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `const_get'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:57:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  20) BeloteDeck behaves like a deck #to_s returns the names of the cards, each on its own line
     Failure/Error: subject(:deck_class) { Object.const_get(klass) }
     NameError:
       uninitialized constant BeloteDeck
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:191
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `const_get'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:68:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  21) BeloteDeck #sort sorts the cards in the defined order
     Failure/Error: deck = BeloteDeck.new(cards)
     NameError:
       uninitialized constant BeloteDeck
     # /tmp/d20151112-27349-1wz1bad/spec.rb:204:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  22) BeloteDeck hand #deal deals 8 cards
     Failure/Error: hand = BeloteDeck.new.deal
     NameError:
       uninitialized constant BeloteDeck
     # /tmp/d20151112-27349-1wz1bad/spec.rb:213:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  23) BeloteDeck hand #highest_of_suit returns the strongest card of the specified suit
     Failure/Error: hand = BeloteDeck.new([
     NameError:
       uninitialized constant BeloteDeck
     # /tmp/d20151112-27349-1wz1bad/spec.rb:221:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  24) BeloteDeck hand #belote? returns true if there is a king and a queen of the same suit
     Failure/Error: hand = BeloteDeck.new([
     NameError:
       uninitialized constant BeloteDeck
     # /tmp/d20151112-27349-1wz1bad/spec.rb:240:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  25) BeloteDeck hand #belote? returns false when there is no king and queen of the same suit
     Failure/Error: hand = BeloteDeck.new([
     NameError:
       uninitialized constant BeloteDeck
     # /tmp/d20151112-27349-1wz1bad/spec.rb:255:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  26) BeloteDeck hand #tierce? with tierce returns true for cards with names
     Failure/Error: hand = BeloteDeck.new([
     NameError:
       uninitialized constant BeloteDeck
     # /tmp/d20151112-27349-1wz1bad/spec.rb:273:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  27) BeloteDeck hand #tierce? with tierce returns true for cards with numbers
     Failure/Error: hand = BeloteDeck.new([
     NameError:
       uninitialized constant BeloteDeck
     # /tmp/d20151112-27349-1wz1bad/spec.rb:288:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  28) BeloteDeck hand #tierce? without tierce does not confuse cards with different suits
     Failure/Error: hand = BeloteDeck.new([
     NameError:
       uninitialized constant BeloteDeck
     # /tmp/d20151112-27349-1wz1bad/spec.rb:305:in `block (5 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  29) BeloteDeck hand #quarte? detects four cards with increasing ranks
     Failure/Error: hand = BeloteDeck.new([
     NameError:
       uninitialized constant BeloteDeck
     # /tmp/d20151112-27349-1wz1bad/spec.rb:323:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  30) BeloteDeck hand #quarte? does not return true if there is no quarte
     Failure/Error: hand = BeloteDeck.new([
     NameError:
       uninitialized constant BeloteDeck
     # /tmp/d20151112-27349-1wz1bad/spec.rb:338:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  31) BeloteDeck hand #quint? detects five cards with increasing ranks
     Failure/Error: hand = BeloteDeck.new([
     NameError:
       uninitialized constant BeloteDeck
     # /tmp/d20151112-27349-1wz1bad/spec.rb:355:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  32) BeloteDeck hand #quint? does not return true if there is no quint
     Failure/Error: hand = BeloteDeck.new([
     NameError:
       uninitialized constant BeloteDeck
     # /tmp/d20151112-27349-1wz1bad/spec.rb:370:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  33) BeloteDeck hand #carre_of_jacks? behaves like carre-checking method returns true when there is a carre
     Failure/Error: hand = BeloteDeck.new([
     NameError:
       uninitialized constant BeloteDeck
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-1wz1bad/spec.rb:386
     # /tmp/d20151112-27349-1wz1bad/spec.rb:75:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  34) BeloteDeck hand #carre_of_jacks? behaves like carre-checking method returns false when there is no carre
     Failure/Error: hand = BeloteDeck.new([
     NameError:
       uninitialized constant BeloteDeck
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-1wz1bad/spec.rb:386
     # /tmp/d20151112-27349-1wz1bad/spec.rb:90:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  35) BeloteDeck hand #carre_of_nines? behaves like carre-checking method returns true when there is a carre
     Failure/Error: hand = BeloteDeck.new([
     NameError:
       uninitialized constant BeloteDeck
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-1wz1bad/spec.rb:390
     # /tmp/d20151112-27349-1wz1bad/spec.rb:75:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  36) BeloteDeck hand #carre_of_nines? behaves like carre-checking method returns false when there is no carre
     Failure/Error: hand = BeloteDeck.new([
     NameError:
       uninitialized constant BeloteDeck
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-1wz1bad/spec.rb:390
     # /tmp/d20151112-27349-1wz1bad/spec.rb:90:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  37) BeloteDeck hand #carre_of_aces? behaves like carre-checking method returns true when there is a carre
     Failure/Error: hand = BeloteDeck.new([
     NameError:
       uninitialized constant BeloteDeck
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-1wz1bad/spec.rb:394
     # /tmp/d20151112-27349-1wz1bad/spec.rb:75:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  38) BeloteDeck hand #carre_of_aces? behaves like carre-checking method returns false when there is no carre
     Failure/Error: hand = BeloteDeck.new([
     NameError:
       uninitialized constant BeloteDeck
     Shared Example Group: "carre-checking method" called from /tmp/d20151112-27349-1wz1bad/spec.rb:394
     # /tmp/d20151112-27349-1wz1bad/spec.rb:90:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  39) SixtySixDeck behaves like a deck implements Enumerable
     Failure/Error: subject(:deck_class) { Object.const_get(klass) }
     NameError:
       uninitialized constant SixtySixDeck
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:400
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `const_get'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:9:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  40) SixtySixDeck behaves like a deck fills the deck if no initialize parameters are given
     Failure/Error: subject(:deck_class) { Object.const_get(klass) }
     NameError:
       uninitialized constant SixtySixDeck
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:400
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `const_get'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:15:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  41) SixtySixDeck behaves like a deck #size returns the size of the deck
     Failure/Error: subject(:deck_class) { Object.const_get(klass) }
     NameError:
       uninitialized constant SixtySixDeck
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:400
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `const_get'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:23:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  42) SixtySixDeck behaves like a deck #draw_top_card pops the top-most card
     Failure/Error: subject(:deck_class) { Object.const_get(klass) }
     NameError:
       uninitialized constant SixtySixDeck
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:400
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `const_get'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:29:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  43) SixtySixDeck behaves like a deck #draw_bottom_card pops the bottom-most card
     Failure/Error: subject(:deck_class) { Object.const_get(klass) }
     NameError:
       uninitialized constant SixtySixDeck
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:400
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `const_get'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:36:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  44) SixtySixDeck behaves like a deck #top peeks at the top-most card
     Failure/Error: subject(:deck_class) { Object.const_get(klass) }
     NameError:
       uninitialized constant SixtySixDeck
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:400
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `const_get'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:43:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  45) SixtySixDeck behaves like a deck #bottom peeks at the bottom-most card
     Failure/Error: subject(:deck_class) { Object.const_get(klass) }
     NameError:
       uninitialized constant SixtySixDeck
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:400
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `const_get'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:50:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  46) SixtySixDeck behaves like a deck #shuffle does not remove cards from the deck
     Failure/Error: subject(:deck_class) { Object.const_get(klass) }
     NameError:
       uninitialized constant SixtySixDeck
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:400
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `const_get'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:57:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  47) SixtySixDeck behaves like a deck #to_s returns the names of the cards, each on its own line
     Failure/Error: subject(:deck_class) { Object.const_get(klass) }
     NameError:
       uninitialized constant SixtySixDeck
     Shared Example Group: "a deck" called from /tmp/d20151112-27349-1wz1bad/spec.rb:400
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `const_get'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:6:in `block (2 levels) in <top (required)>'
     # /tmp/d20151112-27349-1wz1bad/spec.rb:68:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  48) SixtySixDeck #sort sorts the cards in the defined order
     Failure/Error: deck = SixtySixDeck.new(cards)
     NameError:
       uninitialized constant SixtySixDeck
     # /tmp/d20151112-27349-1wz1bad/spec.rb:413:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  49) SixtySixDeck hand #deal deals 6 cards
     Failure/Error: hand = SixtySixDeck.new.deal
     NameError:
       uninitialized constant SixtySixDeck
     # /tmp/d20151112-27349-1wz1bad/spec.rb:422:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  50) SixtySixDeck hand #twenty? returns true for king and queen not of the trump suit
     Failure/Error: hand = SixtySixDeck.new([
     NameError:
       uninitialized constant SixtySixDeck
     # /tmp/d20151112-27349-1wz1bad/spec.rb:430:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  51) SixtySixDeck hand #twenty? returns false for king and queen of the trump suit
     Failure/Error: hand = SixtySixDeck.new([
     NameError:
       uninitialized constant SixtySixDeck
     # /tmp/d20151112-27349-1wz1bad/spec.rb:443:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  52) SixtySixDeck hand #twenty? returns false for hands without a king and queen of the same suit
     Failure/Error: hand = SixtySixDeck.new([
     NameError:
       uninitialized constant SixtySixDeck
     # /tmp/d20151112-27349-1wz1bad/spec.rb:456:in `block (4 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.0853 seconds
57 examples, 52 failures

Failed examples:

rspec /tmp/d20151112-27349-1wz1bad/spec.rb:8 # WarDeck behaves like a deck implements Enumerable
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:14 # WarDeck behaves like a deck fills the deck if no initialize parameters are given
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:22 # WarDeck behaves like a deck #size returns the size of the deck
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:28 # WarDeck behaves like a deck #draw_top_card pops the top-most card
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:35 # WarDeck behaves like a deck #draw_bottom_card pops the bottom-most card
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:42 # WarDeck behaves like a deck #top peeks at the top-most card
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:49 # WarDeck behaves like a deck #bottom peeks at the bottom-most card
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:56 # WarDeck behaves like a deck #shuffle does not remove cards from the deck
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:67 # WarDeck behaves like a deck #to_s returns the names of the cards, each on its own line
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:145 # WarDeck #sort sorts the cards in the defined order
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:161 # WarDeck hand #deal deals 26 cards
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:8 # BeloteDeck behaves like a deck implements Enumerable
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:14 # BeloteDeck behaves like a deck fills the deck if no initialize parameters are given
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:22 # BeloteDeck behaves like a deck #size returns the size of the deck
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:28 # BeloteDeck behaves like a deck #draw_top_card pops the top-most card
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:35 # BeloteDeck behaves like a deck #draw_bottom_card pops the bottom-most card
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:42 # BeloteDeck behaves like a deck #top peeks at the top-most card
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:49 # BeloteDeck behaves like a deck #bottom peeks at the bottom-most card
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:56 # BeloteDeck behaves like a deck #shuffle does not remove cards from the deck
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:67 # BeloteDeck behaves like a deck #to_s returns the names of the cards, each on its own line
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:196 # BeloteDeck #sort sorts the cards in the defined order
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:212 # BeloteDeck hand #deal deals 8 cards
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:220 # BeloteDeck hand #highest_of_suit returns the strongest card of the specified suit
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:239 # BeloteDeck hand #belote? returns true if there is a king and a queen of the same suit
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:254 # BeloteDeck hand #belote? returns false when there is no king and queen of the same suit
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:272 # BeloteDeck hand #tierce? with tierce returns true for cards with names
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:287 # BeloteDeck hand #tierce? with tierce returns true for cards with numbers
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:304 # BeloteDeck hand #tierce? without tierce does not confuse cards with different suits
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:322 # BeloteDeck hand #quarte? detects four cards with increasing ranks
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:337 # BeloteDeck hand #quarte? does not return true if there is no quarte
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:354 # BeloteDeck hand #quint? detects five cards with increasing ranks
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:369 # BeloteDeck hand #quint? does not return true if there is no quint
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:74 # BeloteDeck hand #carre_of_jacks? behaves like carre-checking method returns true when there is a carre
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:89 # BeloteDeck hand #carre_of_jacks? behaves like carre-checking method returns false when there is no carre
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:74 # BeloteDeck hand #carre_of_nines? behaves like carre-checking method returns true when there is a carre
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:89 # BeloteDeck hand #carre_of_nines? behaves like carre-checking method returns false when there is no carre
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:74 # BeloteDeck hand #carre_of_aces? behaves like carre-checking method returns true when there is a carre
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:89 # BeloteDeck hand #carre_of_aces? behaves like carre-checking method returns false when there is no carre
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:8 # SixtySixDeck behaves like a deck implements Enumerable
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:14 # SixtySixDeck behaves like a deck fills the deck if no initialize parameters are given
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:22 # SixtySixDeck behaves like a deck #size returns the size of the deck
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:28 # SixtySixDeck behaves like a deck #draw_top_card pops the top-most card
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:35 # SixtySixDeck behaves like a deck #draw_bottom_card pops the bottom-most card
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:42 # SixtySixDeck behaves like a deck #top peeks at the top-most card
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:49 # SixtySixDeck behaves like a deck #bottom peeks at the bottom-most card
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:56 # SixtySixDeck behaves like a deck #shuffle does not remove cards from the deck
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:67 # SixtySixDeck behaves like a deck #to_s returns the names of the cards, each on its own line
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:405 # SixtySixDeck #sort sorts the cards in the defined order
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:421 # SixtySixDeck hand #deal deals 6 cards
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:429 # SixtySixDeck hand #twenty? returns true for king and queen not of the trump suit
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:442 # SixtySixDeck hand #twenty? returns false for king and queen of the trump suit
rspec /tmp/d20151112-27349-1wz1bad/spec.rb:455 # SixtySixDeck hand #twenty? returns false for hands without a king and queen of the same suit

История (2 версии и 2 коментара)

Кристиян обнови решението на 11.11.2015 14:54 (преди около 9 години)

+module Rules
+ def get_rank
+ all_ranks = {jack: 11, queen: 12, king: 13, ace: 14}
+
+ case rank
+ when 2..10
+ rank
+ else
+ all_ranks[rank]
+ end
+ end
+
+ def get_suit
+ all_suits = {spades: 4, hearts: 3, diamonds: 2, clubs: 1}
+ all_suits[suit]
+ end
+end
+
+module CardGenerator
+ module_function
+ @all_ranks = {jack: 11, queen: 12, king: 13, ace: 14}
+
+ def generate(first = 2)
+ clubs(first) + diamonds(first) + hearts(first) + spades(first)
+ end
+
+ def clubs(first)
+ all_clubs = (first..10).to_a
+ @all_ranks.keys.each { |rank| all_clubs << rank.to_sym}
+ generated_clubs = []
+ all_clubs.each {|club| generated_clubs << Card.new(club, :clubs)}
+ generated_clubs
+ end
+
+ def diamonds(first)
+ all_diamonds = (first..10).to_a
+ @all_ranks.keys.each { |rank| all_diamonds << rank.to_sym.to_sym}
+ generated_diamonds = []
+ all_diamonds.each {|club| generated_diamonds << Card.new(club, :diamonds)}
+ generated_diamonds
+ end
+
+ def hearts(first)
+ all_hearts = (first..10).to_a
+ @all_ranks.keys.each { |rank| all_hearts << rank.to_sym}
+ generated_hearts = []
+ all_hearts.each {|club| generated_hearts << Card.new(club, :hearts)}
+ generated_hearts
+ end
+
+ def spades(first)
+ all_spades = (first..10).to_a
+ @all_ranks.keys.each { |rank| all_spades << rank.to_sym}
+ generated_spades = []
+ all_spades.each {|club| generated_spades << Card.new(club, :spades)}
+ generated_spades
+ end
+end
+
+class Card
+ include Rules
+
+ @suit
+ @rank
+
+ def initialize(card_rank, card_suit)
+ @suit = card_suit
+ @rank = card_rank
+ end
+
+ def rank
+ @rank
+ end
+
+ def suit
+ @suit
+ end
+
+ def ==(other_card)
+ rank == other_card.rank and suit == other_card.suit
+ end
+
+ def to_s
+ case rank
+ when 2..10
+ "#{@rank} of #{@suit.capitalize}"
+ else
+ "#{@rank.capitalize} of #{@suit.capitalize}"
+ end
+ end
+end
+
+class Deck
+ include Enumerable
+ include CardGenerator
+
+ @deck
+
+ def initialize(starting_deck = [])
+ if starting_deck.empty?
+ @deck = CardGenerator.generate
+ else
+ @deck = starting_deck
+ end
+ end
+
+ def deck
+ @deck
+ end
+
+ def size
+ @deck.length
+ end
+
+ def deal(number_of_cards)
+ hand = []
+ shuffle
+ while number_of_cards > 0 and deck.size > 0
+ number_of_cards -= 1
+ hand << draw_top_card
+ end
+ Deck.new(hand)
+ end
+
+ def draw_top_card
+ @deck.delete_at(0)
+ end
+
+ def draw_bottom_card
+ @deck.delete_at(-1)
+ end
+
+ def top_card
+ @deck[0]
+ end
+
+ def bottom_card
+ @deck[-1]
+ end
+
+ def shuffle
+ @deck.shuffle!
+ end
+
+ def sort
+ @deck.sort! { |x, y| y.get_rank <=> x.get_rank }
+ @deck.sort! { |x, y| y.get_suit <=> x.get_suit }
+ end
+
+ def to_s
+ puts @deck
+ end
+
+ def each
+ current = 0
+ while current < deck.length
+ yield deck[current]
+ current += 1
+ end
+ end
+end
+
+class WarDeck < Deck
+ @war_deck
+
+ def initialize(starting_deck = Deck.new)
+ @war_deck = starting_deck
+ end
+
+ def get_deck
+ @war_deck.deck
+ end
+
+ def to_s
+ puts @war_deck.deck
+ end
+
+ def deal
+ WarDeck.new(@war_deck.deal(26))
+ end
+
+ def play_card
+ get_deck.delete_at(0)
+ end
+
+def allow_face_up?
+ get_deck.length <= 3
+ end
+end

Кристиян обнови решението на 11.11.2015 14:54 (преди около 9 години)

module Rules
def get_rank
all_ranks = {jack: 11, queen: 12, king: 13, ace: 14}
case rank
when 2..10
rank
else
all_ranks[rank]
end
end
def get_suit
all_suits = {spades: 4, hearts: 3, diamonds: 2, clubs: 1}
all_suits[suit]
end
end
module CardGenerator
module_function
@all_ranks = {jack: 11, queen: 12, king: 13, ace: 14}
def generate(first = 2)
clubs(first) + diamonds(first) + hearts(first) + spades(first)
end
def clubs(first)
all_clubs = (first..10).to_a
@all_ranks.keys.each { |rank| all_clubs << rank.to_sym}
generated_clubs = []
all_clubs.each {|club| generated_clubs << Card.new(club, :clubs)}
generated_clubs
end
def diamonds(first)
all_diamonds = (first..10).to_a
@all_ranks.keys.each { |rank| all_diamonds << rank.to_sym.to_sym}
generated_diamonds = []
all_diamonds.each {|club| generated_diamonds << Card.new(club, :diamonds)}
generated_diamonds
end
def hearts(first)
all_hearts = (first..10).to_a
@all_ranks.keys.each { |rank| all_hearts << rank.to_sym}
generated_hearts = []
all_hearts.each {|club| generated_hearts << Card.new(club, :hearts)}
generated_hearts
end
def spades(first)
all_spades = (first..10).to_a
@all_ranks.keys.each { |rank| all_spades << rank.to_sym}
generated_spades = []
all_spades.each {|club| generated_spades << Card.new(club, :spades)}
generated_spades
end
end
class Card
include Rules
@suit
@rank
def initialize(card_rank, card_suit)
@suit = card_suit
@rank = card_rank
end
def rank
@rank
end
def suit
@suit
end
def ==(other_card)
rank == other_card.rank and suit == other_card.suit
end
def to_s
case rank
when 2..10
"#{@rank} of #{@suit.capitalize}"
else
"#{@rank.capitalize} of #{@suit.capitalize}"
end
end
end
class Deck
include Enumerable
include CardGenerator
@deck
def initialize(starting_deck = [])
if starting_deck.empty?
@deck = CardGenerator.generate
else
@deck = starting_deck
end
end
def deck
@deck
end
def size
@deck.length
end
def deal(number_of_cards)
hand = []
shuffle
while number_of_cards > 0 and deck.size > 0
number_of_cards -= 1
hand << draw_top_card
end
Deck.new(hand)
end
def draw_top_card
@deck.delete_at(0)
end
def draw_bottom_card
@deck.delete_at(-1)
end
def top_card
@deck[0]
end
def bottom_card
@deck[-1]
end
def shuffle
@deck.shuffle!
end
def sort
@deck.sort! { |x, y| y.get_rank <=> x.get_rank }
@deck.sort! { |x, y| y.get_suit <=> x.get_suit }
end
def to_s
puts @deck
end
def each
current = 0
while current < deck.length
yield deck[current]
current += 1
end
end
end
class WarDeck < Deck
@war_deck
def initialize(starting_deck = Deck.new)
@war_deck = starting_deck
end
def get_deck
@war_deck.deck
end
def to_s
puts @war_deck.deck
end
def deal
WarDeck.new(@war_deck.deal(26))
end
def play_card
get_deck.delete_at(0)
end
-def allow_face_up?
- get_deck.length <= 3
- end
+ def allow_face_up?
+ get_deck.length <= 3
+ end
end

Това ще ти струва наказателна точка, ако не го оправиш.

Причината е, че идентираш с табове, а не с два интервала, както ръководството изисква. Ако ползваш Sublime, виж това. Направи и find & replace на таб с два интервала в текущия си код.