{"action":"created","issue":{"url":"https://api.github.com/repos/brentmartin/BlackJack/issues/1","repository_url":"https://api.github.com/repos/brentmartin/BlackJack","labels_url":"https://api.github.com/repos/brentmartin/BlackJack/issues/1/labels{/name}","comments_url":"https://api.github.com/repos/brentmartin/BlackJack/issues/1/comments","events_url":"https://api.github.com/repos/brentmartin/BlackJack/issues/1/events","html_url":"https://github.com/brentmartin/BlackJack/pull/1","id":160097347,"number":1,"title":"Refactor to better understand classes","user":{"login":"Jack-Barry","id":8129489,"avatar_url":"https://avatars.githubusercontent.com/u/8129489?v=3","gravatar_id":"","url":"https://api.github.com/users/Jack-Barry","html_url":"https://github.com/Jack-Barry","followers_url":"https://api.github.com/users/Jack-Barry/followers","following_url":"https://api.github.com/users/Jack-Barry/following{/other_user}","gists_url":"https://api.github.com/users/Jack-Barry/gists{/gist_id}","starred_url":"https://api.github.com/users/Jack-Barry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jack-Barry/subscriptions","organizations_url":"https://api.github.com/users/Jack-Barry/orgs","repos_url":"https://api.github.com/users/Jack-Barry/repos","events_url":"https://api.github.com/users/Jack-Barry/events{/privacy}","received_events_url":"https://api.github.com/users/Jack-Barry/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-06-14T04:56:44Z","updated_at":"2016-06-17T21:50:47Z","closed_at":"2016-06-16T16:37:48Z","pull_request":{"url":"https://api.github.com/repos/brentmartin/BlackJack/pulls/1","html_url":"https://github.com/brentmartin/BlackJack/pull/1","diff_url":"https://github.com/brentmartin/BlackJack/pull/1.diff","patch_url":"https://github.com/brentmartin/BlackJack/pull/1.patch"},"body":"I refactored as much as I could within the evening here (just looked at the clock and need to get sleep, ha.)  I'd still like to clean up those `p_count` and `c_count` methods, but they aren't as easy to refactor as the `deal` method was.\r\n\r\nI noticed that all of the variables and methods were the same between the `Player` and `Dealer` classes, so I just made the `@computer` another instance of a `Player` and did away with the `Dealer` class.\r\n\r\nIt'll probably be easiest to look at this commit by commit to see where I was going with it, the `Reorder methods` commit was basically nuking everything, as was the `Split methods into separate files` so they might obscure what all was done here.\r\n\r\nLet me know if you have any questions on it, I might mess around with it a bit more tomorrow or throughout the week.\r\n\r\nCheers"},"comment":{"url":"https://api.github.com/repos/brentmartin/BlackJack/issues/comments/226889994","html_url":"https://github.com/brentmartin/BlackJack/pull/1#issuecomment-226889994","issue_url":"https://api.github.com/repos/brentmartin/BlackJack/issues/1","id":226889994,"user":{"login":"Jack-Barry","id":8129489,"avatar_url":"https://avatars.githubusercontent.com/u/8129489?v=3","gravatar_id":"","url":"https://api.github.com/users/Jack-Barry","html_url":"https://github.com/Jack-Barry","followers_url":"https://api.github.com/users/Jack-Barry/followers","following_url":"https://api.github.com/users/Jack-Barry/following{/other_user}","gists_url":"https://api.github.com/users/Jack-Barry/gists{/gist_id}","starred_url":"https://api.github.com/users/Jack-Barry/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Jack-Barry/subscriptions","organizations_url":"https://api.github.com/users/Jack-Barry/orgs","repos_url":"https://api.github.com/users/Jack-Barry/repos","events_url":"https://api.github.com/users/Jack-Barry/events{/privacy}","received_events_url":"https://api.github.com/users/Jack-Barry/received_events","type":"User","site_admin":false},"created_at":"2016-06-17T21:50:47Z","updated_at":"2016-06-17T21:50:47Z","body":"```\r\ncurrent_folder = File.expand_path('../../', __FILE__)\r\nDir[\"#{current_folder}/**/*.rb\"].each { |f| require f }\r\n```\r\nThe first line creates a variable to hold the path of your project root folder.  `__FILE__` is kind of magical as it gives the name of the file it's inside of.  Here, `__FILE__` is passed as an argument to `expand_path` which turns a relative path into an absolute path.  Since `__FILE__` gets modified by the first argument `'../../'`, the relative path being expanded is the `BlackJack` directory.\r\n\r\nThe second line spits out a `require` statement for every file ending in `.rb` within any subdirectory of `current_folder`.\r\n\r\n```\r\ndef board_val(wins)\r\n  \"%02d\" % wins\r\nend\r\n```\r\nHere, the modulo is not behaving as a mathematical operator.  What happens is you create a placeholder within the string, much like use of `#{ }`. `%02d` reserves a space that will have 2 digits and adds leading zeros, `%03d` would have 3 digits with leading zeros, and so on.  The `%` after the string denotes that the following argument(s) will replace the `%` placeholder in the string.\r\n\r\nHaha, `yield` is pretty gnarly, it's true.\r\n\r\nTo explain `p_wins` and `c_wins`:  `@player` is an instance of the `Player` class.  \r\nEach `Player` has a variable `@wins` which in this case can be accessed by calling `@player.wins` which is initially 0.  \r\nEach `Player` also has the method `wins_game` which can be called using `@player.wins_game`.  \r\nEvery time the method is called, it increments `@player.wins` by 1.\r\n\r\nI think what may have been happening is originally, the `Player` class had an instance variable `@p_wins` and then in the program `@p_wins` gets reassigned to refer to `@player.wins`.  I'm not sure exactly what was going on there but feel like that might have had a bit to do with it."}}
{"actor":{"display_login":"Jack-Barry"}}