In ruby, how can I convert a function response into array for later usage?
array = []
def function (subject1)
results = client.get('/subjects', :genre => subject1)
results.each { |r| puts r.title }
array << r.title
end
function(subject1)
My code looks like something similar above. My results however are never stored. Please and thanks for your help :)
results = client.get(...)return intoresults? Is it already an array? It's at least enumerable, since you're doingresults.each...results.map(&:title)as the last line in place of...eachandarray <<...this will return anArrayof alltitlesfromresultsso really it could be 1 lineclient.get('/subjects', :genre => subject1).map(&:title)will have the same result. The you just store it in a variablea = function(subject1)