Class: ConlangWordGenerator::Maybe
- Inherits:
-
Object
- Object
- ConlangWordGenerator::Maybe
- Defined in:
- lib/conlang/operators.rb
Instance Method Summary collapse
- #+(other) ⇒ Object
-
#initialize(weight, set) ⇒ Maybe
constructor
A new instance of Maybe.
- #sample ⇒ Object
Constructor Details
#initialize(weight, set) ⇒ Maybe
Returns a new instance of Maybe.
67 68 69 70 71 72 73 74 75 |
# File 'lib/conlang/operators.rb', line 67 def initialize(weight, set) unless weight > 0 and weight < 100 raise LangSyntaxError, "Weight for an maybe() operator " + "must be between 1 and 100 (exclusive)." end @weight = weight @set = set end |
Instance Method Details
#+(other) ⇒ Object
85 86 87 |
# File 'lib/conlang/operators.rb', line 85 def +(other) Append.new(self, other) end |
#sample ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/conlang/operators.rb', line 77 def sample if rand(100) < @weight @set.sample else "" end end |