カードゲームをモデル化するのにstate_machine gemを使用しています。カードを描画するときにイベント引数を知る必要がある遷移条件があります。ここにいくつかのコード例があります。私は代替を考えていstate_machineを使用している場合、どうすればイベント引数にアクセスできますか?if lambda
class CardGame
state_machine do
before_transition :drawing_card => any, :do => :drawn_card
event :draw_card
transition :drawing_card => :end_of_round, :if => lambda {|game|
# Check goes here, I require knowing which card was taken
# which is passed as arguments to the event (:ace, :spaces)
}
end
end
def drawn_card(value, suit)
# I can access the event arguments in the transition callbacks
end
end
game = CardGame.new
game.draw_card(:ace, :spades)
は、変数として、オブジェクト上のカードのスーツと値を設定することですが、それはイベントに引数を使用するよりも、はるかに乱雑です。事前に
感謝:)
+1私はOllyに同意します。私がstate_machineの限界を回避しようとしているのであれば、間違った目的のために使用していると思われます。ここでの良いインジケータは、あなたが呼ばれている状態です:drawing_cardは、ゲームの状態に似ているのではなく、むしろデッキのデッキがそれ自身の中にあるかもしれないインジケータです。 。 – james2m