Class: Numeric

Inherits:
Object show all
Defined in:
lib/core_ext/numeric.rb

Instance Method Summary collapse

Instance Method Details

#percentbool

Returns true with probability self

Examples:

30.percent  # => true or false
0.percent   # => false
100.percent # => true

Returns:

  • (bool)

8
9
10
# File 'lib/core_ext/numeric.rb', line 8

def percent
  Random.rand(0.0 ... 100) < self
end