Class: LaunchDarkly::Impl::Sampler
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::Sampler
- Defined in:
- lib/ldclient-rb/impl/sampler.rb
Overview
Instance Method Summary collapse
-
#initialize(random) ⇒ Sampler
constructor
A new instance of Sampler.
- #sample(ratio) ⇒ Boolean
Constructor Details
#initialize(random) ⇒ Sampler
Returns a new instance of Sampler.
7 8 9 |
# File 'lib/ldclient-rb/impl/sampler.rb', line 7 def initialize(random) @random = random end |
Instance Method Details
#sample(ratio) ⇒ Boolean
16 17 18 19 20 21 22 |
# File 'lib/ldclient-rb/impl/sampler.rb', line 16 def sample(ratio) return false unless ratio.is_a? Integer return false if ratio <= 0 return true if ratio == 1 @random.rand(1.0) < 1.0 / ratio end |