Class: LOTTO::L

Inherits:
Object
  • Object
show all
Defined in:
lib/toychest/lotto.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#ticketObject (readonly)

Returns the value of attribute ticket.



16
17
18
# File 'lib/toychest/lotto.rb', line 16

def ticket
  @ticket
end

Instance Method Details

#runObject



23
24
25
# File 'lib/toychest/lotto.rb', line 23

def run
  @ticket = LOTTO.digits.sample(LOTTO.size)
end

#win?(w) ⇒ Boolean

Returns:

  • (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