hand.rb
code:ruby
require_relative 'card.rb' # require文の仲間。使いたいclassの定義を読み込んで準備する
# Poker Hand Evaluation
# TODO: Basically, extend this class (you can create another class, of course!)
class Hand
attr_reader :cards, :rank # @cards, @rankという変数を定義し、外部から参照のみ可能にする
def initialize(draw_cards)
# 受け取った配列を分解して、文字列をCardクラスに渡してCardオブジェクトを作成する
@cards = draw_cards.map { |str| Card.new(str) }
# 結果を判定する処理を呼び出す
@rank = categorize
end
private # この指定以降は、外部から直接は呼び出せないメソッドになる
# 今回外部から呼び出す必要はないはずなので、メソッドを追加するならこのあたりがよさそう
# 結果を判定する処理
# このメソッドが大きくわかりにくくなってきたら、適宜分割を相談する
def categorize
'high-card'
end
end