F
F
frolin2014-06-18 19:00:22
ruby
frolin, 2014-06-18 19:00:22

Why does c each work like this in ruby?

found_small = found_page.search('small').each_with_index do | id, i |

 	@uuid = [ i => id ]		
end

puts @uuid

Displays only the last value, and if I insert it into the puts @id loop, it displays - as it should, each line.
Tell me from what? And what is the correct way to make an associative array from a list of strings?
I tried .split("\n") - the same thing doesn't work.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Alekseev, 2014-06-18
@Fralunia

hash = Hash.new
%w(cat dog wombat).each_with_index {|item, index|
  hash[item] = index
}
hash   #=> {"cat"=>0, "dog"=>1, "wombat"=>2}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question