Class: ERV::RandomVariable

Inherits:
Object show all
Extended by:
Forwardable
Defined in:
lib/erv/random_variable.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ RandomVariable

Returns a new instance of RandomVariable.



21
22
23
24
25
26
27
28
29
30
# File 'lib/erv/random_variable.rb', line 21

def initialize(args={})
  # get distribution name
  dist_name = args[:distribution].try(:to_s)

  # get class name that corresponds to the requested distribution
  klass_name = dist_name.split('_').push('distribution').map(&:capitalize).join

  # create distribution object
  @dist = ERV.const_get(klass_name).new(args[:args])
end

Instance Method Details

#nextObject Also known as: sample



32
33
34
# File 'lib/erv/random_variable.rb', line 32

def next
  @dist.sample
end