On Jun 19, 2008, at 9:13 AM, Mike Barton wrote: > I think these methods should both do the same thing. The second works, > however in the first I get errors that string is not matched, where > hash is an instance of String not hash > > def sequences > self.alignment.split(/\n/).inject(Hash.new) do |hash, line| > id, sequence = line.split(/\s+/,2) > # hash.class == String > hash[id] = sequence hash # value of block will be the last expression > > end > end > > def sequences > hash = Hash.new > self.alignment.split(/\n/).each do |line| > id, sequence = line.split(/\s+/,2) > # hash.class == Hash > hash[id] = sequence > end > hash > end The value of the block becomes the first block parameter in the next iteration. -Rob Rob Biedenharn http://agileconsultingllc.com Rob / AgileConsultingLLC.com