Class: Faker::Boolean

Inherits:
Base
  • Object
show all
Defined in:
lib/faker/default/boolean.rb

Constant Summary

Constants inherited from Base

Faker::Base::LLetters, Faker::Base::Letters, Faker::Base::NOT_GIVEN, Faker::Base::Numbers, Faker::Base::ULetters

Class Method Summary collapse

Methods inherited from Base

bothify, disable_enforce_available_locales, fetch, fetch_all, flexible, letterify, method_missing, numerify, parse, rand, rand_in_range, regexify, resolve, respond_to_missing?, sample, shuffle, translate, unique, with_locale

Class Method Details

.boolean(legacy_true_ratio = NOT_GIVEN, 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
21
22
23
# File 'lib/faker/default/boolean.rb', line 18

def boolean(legacy_true_ratio = NOT_GIVEN, true_ratio: 0.5)
  warn_for_deprecated_arguments do |keywords|
    keywords << :true_ratio if legacy_true_ratio != NOT_GIVEN
  end
  (rand < true_ratio)
end