Question

I have a hash that has a keys with multiple values. I would like to create a new files with the key values being the file names. Then I would like to add each value element on a new line of the file.

However I am getting the following error:

`initialize': no implicit conversion of Symbol into String (TypeError)

    @agency_list.each do |domain, email|
        File.open(domain , "w") { |file| file.write(email) }
    end

I tried to convert the value elements to strings but that did not change anything.

Was it helpful?

Solution

It looks like you use symbol in the place where a string should be put into.

Because the information is limited. Try change:

File.open(domain , "w") { |file| file.write(email) }

to

File.open(domain.to_s , "w") { |file| file.write(email) }

and

File.open(domain , "w") { |file| file.write(email.to_s) }

Or add "to_s" to both "domain" and "email" to check which one is correct then you might know which part is wrong.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top