module Statistical::Rng

Factory module to create instances of the various classes nested under itself

Companion RNG class for the continuous uniform distribution. Requires a

distrbution object of the corresponding distribution

@author Vaibhav Yenamandra

@attr_reader [Numeric] lower The lower bound of the uniform distribution. @attr_reader [Numeric] upper The upper bound of the uniform distribution.

Companion RNG class for the continuous Gumbel distribution. Requires a

distrbution object of the corresponding distribution

@author Vaibhav Yenamandra

@attr_reader [Float] location The location parameter of the Gumbel

distribution

@attr_reader [Float] scale The scale parameter of the Gumbel distribution @attr_reader [Float] generator The underlying uniform variate source used

to power `Gumbel#rand`

Public Class Methods

const_missing(cname) click to toggle source

@private No need to document this Dynamically add constants when called

# File lib/statistical/rng.rb, line 20
def self.const_missing(cname)
  const_set(cname, make_classmap) if cname == :RNG_TYPES
end
create(type = :uniform, *args, &block) click to toggle source

Creates a new instance of the give type if the type was found.

@raise ArgumentError If the give type parameter was not found

# File lib/statistical/rng.rb, line 27
def self.create(type = :uniform, *args, &block)
  raise ArgumentError unless RNG_TYPES.include?(type)
  RNG_TYPES[type].new(*args, &block)
end

Private Class Methods

make_classmap() click to toggle source
# File lib/statistical/rng.rb, line 32
def self.make_classmap
  rng_klasses = constants.select { |k| const_get(k).is_a?(Class)}
  keylist = rng_klasses.map { |k| k.to_s.snakecase.to_sym}
  klasses = rng_klasses.map { |k| const_get(k)}
  return Hash[keylist.zip(klasses)].freeze
end