Module: Random::Object
- Defined in:
- lib/gems/facets-2.4.5/lib/more/facets/random.rb
Instance Method Summary collapse
-
#maybe(chance = 0.5, &block) ⇒ Object
Random generator that returns true or false.
Instance Method Details
#maybe(chance = 0.5, &block) ⇒ Object
Random generator that returns true or false. Can also take a block that has a 50/50 chance to being executed.
maybe #=> true
maybe #=> false
88 89 90 91 92 93 94 |
# File 'lib/gems/facets-2.4.5/lib/more/facets/random.rb', line 88 def maybe(chance = 0.5, &block) if block then yield if rand < chance else rand < chance end end |