Skip to content

Instantly share code, notes, and snippets.

@cyril
Forked from jodosha/megalotto.rb
Last active August 29, 2015 14:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cyril/f55e6254d61ea06decd7 to your computer and use it in GitHub Desktop.
Save cyril/f55e6254d61ea06decd7 to your computer and use it in GitHub Desktop.
Thread-safe MegaLotto
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