Module: Kernel
- Defined in:
- lib/alea/kernel.rb
Instance Method Summary collapse
- #almost_always(&block) ⇒ Object
- #almost_never(&block) ⇒ Object
- #chances_of_this_happens(percent = 50.percent, &block) ⇒ Object
- #frequently(&block) ⇒ Object
- #maybe(percent = 50.percent, &block) ⇒ Object
- #probably(&block) ⇒ Object
- #rand_within(range) ⇒ Object
- #rarely(&block) ⇒ Object
Instance Method Details
#almost_always(&block) ⇒ Object
27 28 29 |
# File 'lib/alea/kernel.rb', line 27 def almost_always(&block) chances_of_this_happens 95.percent, &block end |
#almost_never(&block) ⇒ Object
23 24 25 |
# File 'lib/alea/kernel.rb', line 23 def almost_never(&block) chances_of_this_happens 5.percent, &block end |
#chances_of_this_happens(percent = 50.percent, &block) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/alea/kernel.rb', line 31 def chances_of_this_happens(percent = 50.percent, &block) if block_given? percent.chance.of &block else percent.chance.happens? end end |
#frequently(&block) ⇒ Object
11 12 13 |
# File 'lib/alea/kernel.rb', line 11 def frequently(&block) chances_of_this_happens 75.percent, &block end |
#maybe(percent = 50.percent, &block) ⇒ Object
7 8 9 |
# File 'lib/alea/kernel.rb', line 7 def maybe(percent = 50.percent, &block) chances_of_this_happens 50.percent, &block end |
#probably(&block) ⇒ Object
15 16 17 |
# File 'lib/alea/kernel.rb', line 15 def probably(&block) chances_of_this_happens 65.percent, &block end |
#rand_within(range) ⇒ Object
3 4 5 |
# File 'lib/alea/kernel.rb', line 3 def rand_within(range) rand(range.max - range.min) + range.min end |
#rarely(&block) ⇒ Object
19 20 21 |
# File 'lib/alea/kernel.rb', line 19 def rarely(&block) chances_of_this_happens 20.percent, &block end |