Class: ConlangWordGenerator::Or
- Inherits:
-
Object
- Object
- ConlangWordGenerator::Or
- Defined in:
- lib/conlang/operators.rb
Overview
Classes for operators and operands.
Instance Method Summary collapse
- #+(other) ⇒ Object
-
#initialize(weight, setA, setB) ⇒ Or
constructor
A new instance of Or.
- #sample ⇒ Object
Constructor Details
#initialize(weight, setA, setB) ⇒ Or
Returns a new instance of Or.
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/conlang/operators.rb', line 24 def initialize(weight, setA, setB) unless weight > 0 and weight < 100 raise LangSyntaxError, "Weight for an or() operator must " + "be between 1 and 100 (exclusive)." end @weight = weight @setA = setA @setB = setB end |
Instance Method Details
#+(other) ⇒ Object
43 44 45 |
# File 'lib/conlang/operators.rb', line 43 def +(other) Append.new(self, other) end |
#sample ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/conlang/operators.rb', line 35 def sample if rand(100) < @weight @setA.sample else @setB.sample end end |