Class: ERV::RandomVariable
- Extended by:
- Forwardable
- Defined in:
- lib/erv/random_variable.rb
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ RandomVariable
constructor
A new instance of RandomVariable.
- #next ⇒ Object (also: #sample)
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
#next ⇒ Object Also known as: sample
32 33 34 |
# File 'lib/erv/random_variable.rb', line 32 def next @dist.sample end |