Class: Percentage::Chance

Inherits:
Object
  • Object
show all
Defined in:
lib/alea/percentage.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(percent) ⇒ Chance

Returns a new instance of Chance.



20
21
22
23
# File 'lib/alea/percentage.rb', line 20

def initialize(percent)
  @odds    = percent.amount
  @happens = @odds > Kernel.rand(100)
end

Instance Attribute Details

#happensObject (readonly) Also known as: happens?

Returns the value of attribute happens.



17
18
19
# File 'lib/alea/percentage.rb', line 17

def happens
  @happens
end

#oddsObject (readonly)

Returns the value of attribute odds.



17
18
19
# File 'lib/alea/percentage.rb', line 17

def odds
  @odds
end

Instance Method Details

#of(&block) ⇒ Object



25
26
27
# File 'lib/alea/percentage.rb', line 25

def of(&block)
  yield if happens?
end