Module: ConditionalRandom

Defined in:
lib/conditional_random.rb,
lib/conditional_random/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.conditionalize(method_name) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/conditional_random.rb', line 6

def self.conditionalize(method_name)
  # Raise error when method is not exists in SecureRandom
  SecureRandom.send(method_name) unless ::SecureRandom.respond_to?(method_name)

  define_singleton_method method_name do |*args, &block|
    begin
      random = ::SecureRandom.send(method_name, *args)
    end until block.nil? || (block && block.call(random))
    random
  end
end