Created
March 20, 2014 16:08
-
-
Save jodosha/9667365 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
module MegaLotto | |
class Configuration | |
attr_accessor :drawing_count | |
def initialize | |
@drawing_count = 6 | |
end | |
end | |
class Drawing | |
attr_accessor :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_writer :configuration | |
end | |
def self.configuration | |
@configuration ||= Configuration.new | |
end | |
def self.reset | |
@configuration = Configuration.new | |
end | |
def self.configure | |
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