Skip to content

Instantly share code, notes, and snippets.

@jodosha
Created March 20, 2014 16:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jodosha/9667365 to your computer and use it in GitHub Desktop.
Save jodosha/9667365 to your computer and use it in GitHub Desktop.
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