Permalink
Browse files

Allow word choosing strategy to be injected into the generator

  • Loading branch information...
1 parent 1d0959e commit f1748e9bd935f84b8db4a04873617b75e76280d8 @georgehemmings committed May 23, 2012
Showing with 3 additions and 2 deletions.
  1. +3 −2 lib/trigram/generator.rb
View
@@ -1,7 +1,8 @@
module Trigram
class Generator
- def initialize(table)
+ def initialize(table, word_chooser = Proc.new { |words| words.sample })
@table = table
+ @word_chooser = word_chooser
end
def generate_new_text(start)
@@ -17,7 +18,7 @@ def generate_new_text(start)
private
def choose_next_word(word_pair)
- @table.lookup(word_pair).sample
+ @word_chooser.call @table.lookup(word_pair)
end
end
end

0 comments on commit f1748e9

Please sign in to comment.