From: Ryan Davis Date: 2011-08-23T04:21:37+09:00 Subject: Re: Possble bug in Ruby parser (Fixnum#times within "case" statement) On Aug 22, 2011, at 01:43 , Iņaki Baz Castillo wrote: > Yes, "kk" method is useless, already said that in my previous example. > My real code looks more like the following: > > > ------------------ > def receive_data(data) > @buffer << data > > while (case @state > when :init > @parser.reset > @parser_nbytes = 0 > @state = :headers > > when :headers > parse_headers > > when :body > get_body > > when :finished > process_request > @state = :init > # return true to continue processing possible TCP remaining data. > true > > when :ignore > false > end) do > end # while > > end Needless complexity is needless and will _always_ bite you sooner or later. Compare: def receive_data(data) @buffer << data @parser.reset @parser_nbytes = 0 parse_headers get_body process_request end catch :done do loop do receive_data get_data end end