Class: ERV::RandomVariable
- Inherits:
-
Object
- Object
- 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.
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/erv/random_variable.rb', line 23 def initialize(args = {}) # get distribution name dist_name = args[:distribution]&.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
34 35 36 |
# File 'lib/erv/random_variable.rb', line 34 def next @dist.sample end |