Class: LOTTO::L
- Inherits:
-
Object
- Object
- LOTTO::L
- Defined in:
- lib/toychest/lotto.rb
Instance Attribute Summary collapse
-
#ticket ⇒ Object
readonly
Returns the value of attribute ticket.
Instance Method Summary collapse
-
#initialize(k) ⇒ L
constructor
A new instance of L.
- #run ⇒ Object
- #win?(w) ⇒ Boolean
Constructor Details
#initialize(k) ⇒ L
Returns a new instance of L.
17 18 19 20 21 22 |
# File 'lib/toychest/lotto.rb', line 17 def initialize k @id = k if !ticket run end end |
Instance Attribute Details
#ticket ⇒ Object (readonly)
Returns the value of attribute ticket.
16 17 18 |
# File 'lib/toychest/lotto.rb', line 16 def ticket @ticket end |
Instance Method Details
#run ⇒ Object
23 24 25 |
# File 'lib/toychest/lotto.rb', line 23 def run @ticket = LOTTO.digits.sample(LOTTO.size) end |
#win?(w) ⇒ Boolean
26 27 28 29 30 |
# File 'lib/toychest/lotto.rb', line 26 def win? w t = 0 w.each { |e| if @ticket.include?(e); t += 1; end } return t end |