Created
December 10, 2010 17:01
-
-
Save vertiginous/736466 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $ruby roullette.rb | |
| 0 | |
| Charlie bet $10 on 13. | |
| He rolled a 29. | |
| His payout is $0. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'httparty' | |
| class Roulette | |
| include HTTParty | |
| base_uri 'roulette.engineyard.com/' | |
| default_timeout 3 | |
| attr_accessor :amount, :numbers | |
| def self.bet(amount) | |
| new.bet(amount) | |
| end | |
| def bet(amount) | |
| @amount = amount | |
| self | |
| end | |
| def on(*numbers) | |
| @numbers = numbers | |
| self | |
| end | |
| def payout | |
| winner? ? (36 - bets_placed)/bets_placed * @amount : 0 | |
| end | |
| def bets_placed | |
| @numbers.count | |
| end | |
| def winner? | |
| @numbers.include? roll | |
| end | |
| def roll | |
| @roll ||= get['winning_number'].to_i | |
| end | |
| def get | |
| self.class.get('').parsed_response | |
| end | |
| def results | |
| "Charlie bet $#{amount} on #{numbers.join(', ')}.\n" << | |
| "He rolled a #{roll}.\n" << | |
| "His payout is $#{payout}." | |
| end | |
| end | |
| puts Roulette.bet(10).on(13).payout | |
| puts Roulette.bet(10).on(13).results | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment