Method: Faker::Boolean.boolean

Defined in:
lib/faker/default/boolean.rb

.boolean(true_ratio: 0.5) ⇒ Boolean

Produces a boolean

Examples:

Faker::Boolean.boolean #=> true
Faker::Boolean.boolean(true_ratio: 0.2) #=> false

Parameters:

  • true_ratio (Float) (defaults to: 0.5)

    The likelihood (as a float, out of 1.0) for the method to return true.

Returns:

Available since:

  • 1.6.2



18
19
20
# File 'lib/faker/default/boolean.rb', line 18

def boolean(true_ratio: 0.5)
  (rand < true_ratio)
end