{"id":28422465,"url":"https://github.com/turingschool-examples/sorting_cards","last_synced_at":"2026-01-20T17:22:56.362Z","repository":{"id":34409853,"uuid":"150147455","full_name":"turingschool-examples/sorting_cards","owner":"turingschool-examples","description":null,"archived":false,"fork":false,"pushed_at":"2023-04-22T23:07:03.000Z","size":5,"stargazers_count":0,"open_issues_count":2,"forks_count":44,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-06-05T07:47:30.464Z","etag":null,"topics":["be-1","project","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/turingschool-examples.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-09-24T18:14:20.000Z","updated_at":"2022-02-22T18:22:15.000Z","dependencies_parsed_at":"2023-02-10T12:31:01.363Z","dependency_job_id":null,"html_url":"https://github.com/turingschool-examples/sorting_cards","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/turingschool-examples/sorting_cards","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/turingschool-examples%2Fsorting_cards","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/turingschool-examples%2Fsorting_cards/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/turingschool-examples%2Fsorting_cards/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/turingschool-examples%2Fsorting_cards/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/turingschool-examples","download_url":"https://codeload.github.com/turingschool-examples/sorting_cards/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/turingschool-examples%2Fsorting_cards/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261575902,"owners_count":23179588,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["be-1","project","ruby"],"created_at":"2025-06-05T07:17:19.231Z","updated_at":"2026-01-20T17:22:56.317Z","avatar_url":"https://github.com/turingschool-examples.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Sorting Cards\n\nIn this project, you will write a program to simulate a deck of cards. We will add functionality to guess what the card on the top of the deck is, and sort the deck.\n\nIn order to build good habits, we've broken the project into small classes to demonstrate objects that have a single responsibility.\n\n## Setup\n\n* Fork [this repository](https://github.com/turingschool-examples/sorting_cards)\n* Clone YOUR fork to your computer\n  * Make sure you don't clone the turingschool-examples repository\n* Complete the iterations below\n  * Remember to commit frequently!\n\n## Submission\n\nWhen you are finished, make sure your code is pushed up to your repository on Github. Submit a Pull Request from your repository to the turingschool-examples repository.\n\n# Iteration 1\n\n### Cards\n\nA `Card` represents a single card in our deck. It stores a suit and a value.\n\nUse the tests provided to drive the development of your `Card` class. From the root directory of your project, run the test like this:\n\n```\nrspec spec/card_spec.rb\n```\n\nIf you haven't already, you will need to install RSpec:\n\n```\ngem install rspec\n```\n\nIf your `Card` class is written properly, you should be able to open a pry session and interact with it like so:\n\n```ruby\npry(main)\u003e require './lib/card'\n#=\u003e true\n\npry(main)\u003e card = Card.new(\"Ace\", \"Spades\")\n#=\u003e #\u003cCard:0x00007f800e29f0c8 @suit=\"Spades\", @value=\"Ace\"\u003e\n\npry(main)\u003e card.value\n#=\u003e \"Ace\"\n\npry(main)\u003e card.suit\n#=\u003e \"Spades\"\n```\n\nThis interaction pattern assumes your `Card` class is in a file located at `./lib/card.rb`.\n\n### Guesses\n\nCreate a `Guess` class and an accompanying test file with the following methods:\n\n* `initialize(string, Card)` - A guess is initialized with two arguments. The first is a string representing a response to a card in the form of `\u003cvalue\u003e of \u003csuit\u003e`. The second argument is a `Card` object representing the card being guessed.\n* `response` - This method returns the response\n* `card` - This method returns the Card\n* `correct?` - This method returns a boolean indicating if the response correctly guesses the value and suit of the Card\n* `feedback` - This method either returns `\"Correct!\"` or `\"Incorrect.\"` based on whether the guess was correct or not\n\nThe `Guess` class should respond to the following interaction pattern:\n\n```ruby\npry(main)\u003e require './lib/guess'\n#=\u003e true\n\npry(main)\u003e require './lib/card'\n#=\u003e true\n\npry(main)\u003e card = Card.new(\"10\", \"Hearts\")\n#=\u003e #\u003cCard:0x00007f9984004cc0 @suit=\"Hearts\", @value=\"10\"\u003e\n\npry(main)\u003e guess = Guess.new(\"10 of Hearts\", card)\n#=\u003e #\u003cGuess:0x00007f99842f0998 @card=#\u003cCard:0x00007f9984004cc0 @suit=\"Hearts\", @value=\"10\"\u003e, @guess=\"10 of Hearts\"\u003e\n\npry(main)\u003e guess.card\n#=\u003e #\u003cCard:0x00007f9984004cc0 @suit=\"Hearts\", @value=\"10\"\u003e\n\npry(main)\u003e guess.response\n#=\u003e \"10 of Hearts\"\n\npry(main)\u003e guess.correct?\n#=\u003e true\n\npry(main)\u003e guess.feedback\n#=\u003e \"Correct!\"\n```\n\nWe also want to make sure that incorrect guesses are handled properly.\n\n```ruby\npry(main)\u003e require './lib/guess'\n#=\u003e true\n\npry(main)\u003e require './lib/card'\n#=\u003e true\n\npry(main)\u003e card = Card.new(\"Queen\", \"Clubs\")\n#=\u003e #\u003cCard:0x00007f99839aa2a8 @suit=\"Clubs\", @value=\"Queen\"\u003e\n\npry(main)\u003e guess = Guess.new(\"2 of Diamonds\", card)\n#=\u003e #\u003cGuess:0x00007f998413ee60 @card=#\u003cCard:0x00007f99839aa2a8 @suit=\"Clubs\", @value=\"Queen\"\u003e, @guess=\"2 of Diamonds\"\u003e\n\npry(main)\u003e guess.card\n=\u003e #\u003cCard:0x00007f99839aa2a8 @suit=\"Clubs\", @value=\"Queen\"\u003e\n\npry(main)\u003e guess.response\n=\u003e \"2 of Diamonds\"\n\npry(main)\u003e guess.correct?\n=\u003e false\n\npry(main)\u003e guess.feedback\n=\u003e \"Incorrect.\"\n```\n\nRemember, `#\u003cGuess:0x00007f998413ee60 ... \u003e` means \"A Guess Obeject\" or \"An Instance of the Guess Class\".\n\n# Iteration 2\n\n### Storing Cards in a Deck\n\nCreate a `Deck` class with an accompanying test file. A `Deck` is initialized with an array of `Card` objects. The `Deck` class should respond to the following interaction pattern:\n\n```ruby\npry(main)\u003e require './lib/card'\n#=\u003e true\n\npry(main)\u003e require './lib/deck'\n#=\u003e true\n\npry(main)\u003e card_1 = Card.new(\"3\",\"Hearts\")\n#=\u003e #\u003cCard:0x00007fa16104e160 @suit=\"Hearts\", @value=\"3\"\u003e\n\npry(main)\u003e card_2 = Card.new(\"4\", \"Clubs\")\n#=\u003e #\u003cCard:0x00007fa160a62e90 @suit=\"Clubs\", @value=\"4\"\u003e\n\npry(main)\u003e card_3 = Card.new(\"5\", \"Diamonds\")\n#=\u003e #\u003cCard:0x00007fa161a136f0 @suit=\"Diamonds\", @value=\"5\"\u003e\n\npry(main)\u003e cards = [card_1, card_2, card_3]\n\npry(main)\u003e deck = Deck.new(cards)\n#=\u003e #\u003cDeck:0x00007fa160a38ed8...\u003e\n\npry(main)\u003e deck.cards\n#=\u003e [#\u003cCard:0x00007fa16104e160...\u003e, #\u003cCard:0x00007fa160a62e90...\u003e, #\u003cCard:0x00007fa161a136f0...\u003e]\n\npry(main)\u003e deck.count\n#=\u003e 3\n```\n\n### The Round\n\nA `Round` will be the object that processes responses and records guesses. A `Round` is initialized with a `Deck`. The idea is that when we start a Round, the current card is the first in the deck (the first in the Deck's array of Cards). When we make a guess, the guess is recorded, and the current card becomes the next card in the deck.\n\nThe `record_guess` method is the crux of this problem. The `record_guess` method takes a hash representing the guess. It should create a new `Guess` object with the appropriate response and Card. It should store this new guess, as well as return it from the `record_guess` method. Also, when the `record_guess` method is called, the `Round` should move on to the next card in the deck.\n\nA `Round` should respond to the following interaction pattern:\n\n```ruby\npry(main)\u003e require './lib/card'\n#=\u003e true\n\npry(main)\u003e require './lib/deck'\n#=\u003e true\n\npry(main)\u003e require './lib/round'\n#=\u003e true\n\npry(main)\u003e card_1 = Card.new(\"3\",\"Hearts\")\n#=\u003e #\u003cCard:0x00007f972a227f18 @suit=\"Hearts\", @value=\"3\"\u003e\n\npry(main)\u003e card_2 = Card.new(\"4\", \"Clubs\")\n#=\u003e #\u003cCard:0x00007f9729a87998 @suit=\"Clubs\", @value=\"4\"\u003e\n\npry(main)\u003e deck = Deck.new([card_1, card_2])\n#=\u003e #\u003cDeck:0x00007f972a214288...\u003e\n\npry(main)\u003e round = Round.new(deck)\n#=\u003e #\u003cRound:0x00007f972a1c7960...\u003e,\n\npry(main)\u003e round.deck\n#=\u003e #\u003cDeck:0x00007f972a214288...\u003e\n\npry(main)\u003e round.guesses\n#=\u003e []\n\npry(main)\u003e round.current_card\n#=\u003e #\u003cCard:0x00007f972a227f18 @suit=\"Hearts\", @value=\"3\"\u003e\n\npry(main)\u003e new_guess = round.record_guess({value: \"3\", suit: \"Hearts\"})\n#=\u003e #\u003cGuess:0x00007f972a15c160 @card=#\u003cCard:0x00007f972a227f18 @suit=\"Hearts\", @value=\"3\"\u003e, @response=\"3 of Hearts\"\u003e\n\npry(main)\u003e new_guess.class\n#=\u003e Guess\n\npry(main)\u003e new_guess.correct?\n#=\u003e true\n\npry(main)\u003e round.guesses\n#=\u003e [#\u003cGuess:0x00007f972a15c160 @card=#\u003cCard:0x00007f972a227f18 @suit=\"Hearts\", @value=\"3\"\u003e, @response=\"3 of Hearts\"\u003e]\n\npry(main)\u003e round.number_correct\n#=\u003e 1\n\npry(main)\u003e round.current_card\n#=\u003e #\u003cCard:0x00007f9729a87998 @suit=\"Clubs\", @value=\"4\"\u003e\n\npry(main)\u003e round.record_guess({value: \"Jack\", suit: \"Diamonds\"})\n#=\u003e #\u003cGuess:0x00007f972a215b38...\u003e\n\npry(main)\u003e round.guesses.count\n#=\u003e 2\n\npry(main)\u003e round.guesses.last.feedback\n#=\u003e \"Incorrect.\"\n\npry(main)\u003e round.number_correct\n#=\u003e 1\n\npry(main)\u003e round.percent_correct\n#=\u003e 50.0\n```\n\n# Iteration 3: Sorting the Deck\n\nIn this iteration, we will start to add some algorithmic complexity. We are going to add to the deck object the ability to sort the cards based on their value from lowest to highest. The order of values from lowest to highest is 2 through 10, Jack, Queen, King, Ace.\n\nIf two cards have the same value, the suit should be used to determine the order they are sorted. The order of suit from lowest to highest is Clubs, Diamonds, Hearts, Spades.\n\nYou are *NOT* allowed to use any built in sorting methods.\n\nThe interaction pattern will look like this:\n\n```ruby\ncard_1 = Card.new(\"4\",\"Hearts\")\ncard_2 = Card.new(\"Ace\", \"Spades\")\ncard_3 = Card.new(\"5\", \"Diamonds\")\ncard_4 = Card.new(\"Jack\", \"Clubs\")\ncard_5 = Card.new(\"Ace\", \"Diamonds\")\ndeck = Deck.new([card_1, card_2, card_3, card_4, card_5])\n\ndeck.sort\n=\u003e [card_1, card_3, card_4, card_5, card_2]\n```\n\n# Iteration 4: Merge Sort\n\nWe're doing the same here, but with a different sorting algorithm, merge sort. As you implement this, think about why we might need different algorithms. How many swaps does your sort from iteration 3 make in the best case scenario? Worst case? How does this compare to Merge Sort?\n\nThe interaction pattern will look like this:\n\n```ruby\ncard_1 = Card.new(\"4\",\"Hearts\")\ncard_2 = Card.new(\"Ace\", \"Spades\")\ncard_3 = Card.new(\"5\", \"Diamonds\")\ncard_4 = Card.new(\"Jack\", \"Clubs\")\ncard_5 = Card.new(\"Ace\", \"Diamonds\")\ndeck = Deck.new([card_1, card_2, card_3, card_4, card_5])\n\ndeck.merge_sort\n=\u003e [card_1, card_3, card_4, card_5, card_2]\n```\n\n### Merge Sort Resources\n\n* [Youtube CS50](https://youtu.be/Pr2Jf83_kG0)\n* [Merge Sort Visualization](https://www.youtube.com/watch?v=ZRPoEKHXTJg)\n* [Folk Dance](https://www.youtube.com/watch?v=XaqR3G_NVoo)\n\n\n# Evaluation Rubric\n\n## Functionality\n\n* Student completes through Iteration 3\n\n## Mechanics\n\nThe student:\n\n* appropriately uses Ruby datatypes to solve a problem (including Strings, Integers, Floats, Ranges, Symbols, Nils, Arrays, and/or Hashes)\n* implements best-choice enumerable methods to iterate over collections\n* uses boolean expressions and flow control structures to logically manage a program's flow\n* uses methods, arguments, and return values to break code into logical components\n* creates Classes that utilize instance variables, attribute accessors, and instance methods\n\n## Design\n\nThe student:\n\n* adheres to the Single Responsibility and DRY principles\n* creates Objects and Classes that appropriately encompass state and behavior\n* uses instance and local variables appropriately\n* writes readable code with the following characteristics:\n    * Variable and method names are self explanatory\n    * Methods are under 7 lines\n    * Lines of code are under 80 characters\n    * Project directory structure adheres to convention (uses `lib` and `spec` folders)\n    * A linter (e.g. Rubocop) reports less than 5 errors\n\n## Testing\n\nThe student:\n\n* writes RSpec tests that describe the expected behavior of a program according to technical specifications\n* names and orders tests so that a test file reads like documentation\n* writes RSpec assertions (`expect` statements) that accurately test a piece of functionality\n* writes a test before writing code that implements the behavior to make that test pass\n* writes both integration and unit tests\n\n## Version Control\n\nThe student:\n\n* hosts their code on the master branch of their remote repository\n* makes commits in small chunks of functionality\n* submits and merges Pull Requests using the Github interface\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fturingschool-examples%2Fsorting_cards","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fturingschool-examples%2Fsorting_cards","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fturingschool-examples%2Fsorting_cards/lists"}