I'm having an issue figuring out how to pass an IO stream to a method.
write_it = File.new("test_ids", "w")
def getid (line, file_info)
find_id = line.split(" ")
find_id.each do |get_id|
if get_id =~ /^id*/
return get_id
else
file_info.puts("No ID.")
return "No ID"
end
end
end
a = "name=example id=stuff"
b = "name=example noid=writefile"
getid(a, write_it)
getid(b, write_it)
I've also tried with def getid(line) thinking maybe I didn't need to
pass an IO stream, but it still doesn't work.
...it's more likely that it has to do with the fact that you do not close the
file handle properly.
This is not the complete code. I close the file further down, as I had
more things to write to it. The problem was that the stream was not
being sent to the method and instead I was getting an error. But it's
working now anyway, thanks.