diff --git a/examples/simple/word_count_bolt.rb b/examples/simple/word_count_bolt.rb index 0a3fd09..697223d 100644 --- a/examples/simple/word_count_bolt.rb +++ b/examples/simple/word_count_bolt.rb @@ -1,32 +1,28 @@ class WordCountBolt < RedStorm::SimpleBolt output_fields :word, :count + on_init {@counts = Hash.new{|h, k| h[k] = 0}} + on_tuple do |tuple| word = tuple.getString(0) @counts[word] += 1 [word, @counts[word]] end - - def initialize - @counts = Hash.new{|h, k| h[k] = 0} - end end +# below is the same bolt but passing a method name to on_tuple + # class WordCountBolt < RedStorm::SimpleBolt - # output_fields :word, :count -# on_tuple :count_word, :ack => true, :anchor => true - +# on_init {@counts = Hash.new{|h, k| h[k] = 0}} +# on_tuple :count_word +# # def count_word(tuple) # word = tuple.getString(0) # @counts[word] += 1 - +# # [word, @counts[word]] # end - -# def initialize -# @counts = Hash.new{|h, k| h[k] = 0} -# end # end