Class: Percentage::Chance
- Inherits:
-
Object
- Object
- Percentage::Chance
- Defined in:
- lib/alea/percentage.rb
Instance Attribute Summary collapse
-
#happens ⇒ Object
(also: #happens?)
readonly
Returns the value of attribute happens.
-
#odds ⇒ Object
readonly
Returns the value of attribute odds.
Instance Method Summary collapse
-
#initialize(percent) ⇒ Chance
constructor
A new instance of Chance.
- #of(&block) ⇒ Object
Constructor Details
#initialize(percent) ⇒ 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
#happens ⇒ Object (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 |
#odds ⇒ Object (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 |