From 8bc08ec5252ae4e8da3739db3586d9d15a91ea52 Mon Sep 17 00:00:00 2001 From: julien Date: Wed, 14 Oct 2026 11:08:11 +0200 Subject: [PATCH] =?UTF-8?q?exercice=20termin=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- exercises/hand_score.rb | 29 +++++++++++++++++++++++++++-- test.rb | 16 ++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 test.rb diff --git a/exercises/hand_score.rb b/exercises/hand_score.rb index c006503..85ed18e 100644 --- a/exercises/hand_score.rb +++ b/exercises/hand_score.rb @@ -23,14 +23,39 @@ cards = [ { value: "7", suit: "clubs" }, { value: "king", suit: "hearts" }, - { value: "ace", suit: "spades" } + { value: "ace", suit: "spades" }, + # { value: "blork", suit: "club"} ] def hand_score(cards) - # À compléter. + score = 0 + + cards.each do |card| + value = Integer(card[:value], exception: false) + if value + score += value + else + case card[:value] + when "jack" + score += 11 + when "queen" + score += 12 + when "king" + score += 13 + when "ace" + score += 14 + else + # raise lève une exception et interrompt l'exécution normale du programme. + raise ArgumentError, "Valeur de carte inconnue : #{card[:value]}" + end + end + end + score end # Résultat attendu : # # hand_score(cards) # => 34 + +puts hand_score(cards) diff --git a/test.rb b/test.rb new file mode 100644 index 0000000..cce43d0 --- /dev/null +++ b/test.rb @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby + +class Test + def initialize(fruit) + @fruit = fruit + end + + def hello + name = "Bob" + puts "Hello #{name} !" + end + + def eat + puts "#{@fruit}" + end +end