Let's write some card games in Ruby!

Neat! I like the way that looks.

1 Like

I got asked about whether CardsLib could do non Rank/Suit type of data. I wrote a test proving that it can with the sample data I was asked about.

it "can take spurious data" do
    # NOTE: You must build custom ranker if you want to take advantage of comparison.
    rank = :Ferrari
    suit = {km_h: 300, hp: 380, cc: 4390, cylinder: "V12", kg: 1120}
    c = Card.new rank: rank, suit: suit
    _(c.face).must_equal "Ferrari of {:km_h=>300, :hp=>380, :cc=>4390, :cylinder=>\"V12\", :kg=>1120}"
    _(c.suit).must_equal suit
    _(c.rank).must_equal rank
  end

And it works. So you can likely do your Magic kind of games with this. But as I don’t know the mechanics of that game I’m not sure how you’d handle comparison (if at all).

1 Like