Class: RandomVariable::Generic

Inherits:
Object
  • Object
show all
Includes:
Sampleable
Defined in:
lib/random_variable.rb

Instance Method Summary collapse

Methods included from Sampleable

#outcome, #outcomes

Constructor Details

#initialize(&blk) ⇒ Generic

Returns a new instance of Generic.



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/random_variable.rb', line 79

def initialize(&blk)
  @blk = blk
  
  class << self
    def outcome
      @blk.call
    end
    alias :sample :outcome

    def outcomes(nr_samples)
      ary = []
      nr_samples.times do
        ary << @blk.call
      end
      class << ary
        include RandomVariable::Samples
      end
      ary
    end
    alias :samples :outcomes
  end
end