-
-
Save cyril/f55e6254d61ea06decd7 to your computer and use it in GitHub Desktop.
Thread-safe MegaLotto
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
module MegaLotto | |
class Configuration | |
attr_accessor :drawing_count | |
def initialize | |
@drawing_count = 6 | |
end | |
end | |
class Drawing | |
attr_reader :config | |
def initialize(config = MegaLotto.configuration) | |
@config = config | |
end | |
def draw | |
config.drawing_count.times.map { single_draw } | |
end | |
private | |
def single_draw | |
rand(0...60) | |
end | |
end | |
class << self | |
attr_accessor :configuration | |
end | |
def self.configure | |
@configuration = Configuration.new | |
yield(configuration) | |
end | |
end | |
MegaLotto.configure do |config| | |
config.drawing_count = 10 | |
end | |
puts MegaLotto::Drawing.new.draw |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment