Class: ERV::RandomVariable
Instance Method Summary collapse
-
#initialize(opts) ⇒ RandomVariable
constructor
A new instance of RandomVariable.
- #next ⇒ Object
Constructor Details
#initialize(opts) ⇒ RandomVariable
Returns a new instance of RandomVariable.
15 16 17 18 19 20 21 22 23 |
# File 'lib/erv/random_variable.rb', line 15 def initialize(opts) # get distribution name dist_name = opts[: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(opts) end |
Instance Method Details
#next ⇒ Object
25 26 27 |
# File 'lib/erv/random_variable.rb', line 25 def next @dist.sample end |