Afficher un message
Vieux 19/06/2008, 15h12   #1
Mike Barton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut I don't really understand inject

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
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



  Réponse avec citation
 
Page generated in 0,06366 seconds with 9 queries