module Statistical::Distribution

Factory module used to create instances of various distributions classes nested under itself

Module to collect all abstractions of distributions

Public Class Methods

const_missing(cname) click to toggle source

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

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

Create a distribution identified by the type hash @raise ArgumentError if `type` was not found

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

Private Class Methods

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