Sha256: fa8412525d8599c333f48dacc625221b601b4cceabb1c585a959392b9778848d

Contents?: true

Size: 316 Bytes

Versions: 17

Compression:

Stored size: 316 Bytes

Contents

module Kernel

  # 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
  #
  def maybe(chance = 0.5, &block)
    if block then
      yield if rand < chance
    else
      rand < chance
    end
  end

end

Version data entries

17 entries across 17 versions & 2 rubygems

Version Path
facets-2.8.4 lib/core/facets/kernel/maybe.rb
facets-2.8.3 lib/core/facets/kernel/maybe.rb
facets-2.8.2 lib/core/facets/kernel/maybe.rb
facets-2.8.1 lib/core/facets/kernel/maybe.rb
facets-2.8.0 lib/core/facets/kernel/maybe.rb
facets-2.7.0 lib/core/facets/kernel/maybe.rb
facets-2.6.0 lib/core/facets/kernel/maybe.rb
facets-2.4.0 lib/facets/kernel/maybe.rb
facets-2.4.1 lib/facets/kernel/maybe.rb
facets-2.4.3 lib/core/facets/kernel/maybe.rb
facets-2.4.4 lib/core/facets/kernel/maybe.rb
facets-2.4.2 lib/core/facets/kernel/maybe.rb
facets-2.5.0 lib/core/facets/kernel/maybe.rb
facets-2.5.1 lib/core/facets/kernel/maybe.rb
facets-2.4.5 lib/core/facets/kernel/maybe.rb
facets-2.5.2 lib/core/facets/kernel/maybe.rb
mack-facets-0.8.2 lib/gems/facets-2.4.5/lib/core/facets/kernel/maybe.rb