I am trying to fill an array of hashes with hashes created through an each loop, If I print each individual hash within the iteration they are distinct, but when I try to push them to an array, the resulting array has the last hash repeated whatever number of times. Here's the code:
def get_tweets
tweet_array = Array.new
tweet = {}
Twitter::Search.new('Accidente' || 'accidente').from('sttmed').each do |r|
tweet["texto"] = r.text
tweet["reportado"] = (Time.parse(r.created_at)).localtime.strftime("%B %d, %H:%M %p %Z")
tweet["direccion"] = r.text.scan(/\w*_\w*/).join
tweet_array << tweet
end
return tweet_array # RETURNS ALL REPEAT VALUES!!
end
I have looked everywhere but I can't seem to find what I'm doing wrong (It's probably a dumb problem but it's stumping this beginner..) I'll appreciate any help!