lib/cf3.rb in cf3-1.0.0 vs lib/cf3.rb in cf3-1.0.1
- old
+ new
@@ -49,22 +49,20 @@
def shape(rule_name, prob = 1, &proc)
@rules[rule_name] ||= { procs: [], total: 0 }
total = @rules[rule_name][:total]
@rules[rule_name][:procs] << [(total...(prob + total)), proc]
@rules[rule_name][:total] += prob
- unless ContextFree.method_defined? rule_name
- self.class.class_eval do
- eval <<-METH
- def #{rule_name}(options)
- merge_options(@values, options)
- pick = determine_rule(#{rule_name.inspect})
- unless (@values[:size] - @values[:stop_size]) < 0
- prepare_to_draw
- pick[1].call(options)
- end
- end
- METH
+ return if ContextFree.method_defined? rule_name
+ self.instance_eval do
+ eval <<-METH
+ def #{rule_name}(options)
+ merge_options(@values, options)
+ pick = determine_rule(#{rule_name.inspect})
+ return if (@values[:size] - @values[:stop_size]) < 0
+ prepare_to_draw
+ pick[1].call(options)
end
+ METH
end
end
# Rule choice is random, based on the assigned probabilities.
def determine_rule(rule_name)