class Randrizer::Types::Nullable
Public Class Methods
new(null_prob:, inner_type:)
click to toggle source
# File lib/randrizer/types/nullable.rb, line 8 def initialize(null_prob:, inner_type:) @null_prob = null_prob @inner_type = inner_type end
Public Instance Methods
eval()
click to toggle source
# File lib/randrizer/types/nullable.rb, line 18 def eval return nil if rand > (1.0 - @null_prob) @inner_type.eval end
validate!()
click to toggle source
# File lib/randrizer/types/nullable.rb, line 13 def validate! raise ValidationError("null_prob must be < 1.0") if @null_prob > 1.0 raise ValidationError("null_prob must be > 0.0") if @null_prob < 0.0 end