I’m very new to Ruby and I’m trying to build a simple function that will search Twitter, grab a certain string with a URL, chop off that string and place the URL only into an empty array.
The end goal of the function is that it returns an array with 2 URLs inside that I can manipulate with another function.
I’ve been staring at this for a while and I’m completely unsure how to turn the arrays that URI::extract spits out into strings and then place them in an array.
Any help is much, much appreciated! Thank you!
require 'rubygems'
require 'twitter'
require 'json'
require 'uri'
require 'mechanize'
def grabTweets()
urls = []
tweets = Twitter.search("[pic] "+" path.com/p/", :rpp => 2, :result_type => "recent").map do |status|
tweets = "#{status.text}" #class = string
url = URI::extract(tweets) #class = array
print url
#turn each array into a string
#place string in array
#what do I return?
end
end
timelineTweets = grabTweets()
URI::extract returns an array of URL Strings. You just have to put its output into your desired array.
You can do that the following way: