File: boolean.rb

package info (click to toggle)
ruby-faker 2.21.0-1.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,076 kB
  • sloc: ruby: 19,088; makefile: 6
file content (26 lines) | stat: -rw-r--r-- 697 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# frozen_string_literal: true

module Faker
  class Boolean < Base
    class << self
      ##
      # Produces a boolean
      #
      # @param true_ratio [Float] The likelihood (as a float, out of 1.0) for the method to return `true`.
      # @return [Boolean]
      #
      # @example
      #   Faker::Boolean.boolean #=> true
      # @example
      #   Faker::Boolean.boolean(true_ratio: 0.2) #=> false
      #
      # @faker.version 1.6.2
      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
    end
  end
end