From 902fb8cb9ca5a33ee295bd4926ba63aaab1a1fa8 Mon Sep 17 00:00:00 2001 From: Colin Surprenant Date: Thu, 10 Nov 2011 17:23:35 -0500 Subject: [PATCH] simpler bolt --- examples/simple/word_count_bolt.rb | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) 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