If you do not want a for loop I guess you could modify the method as such. I'm figuring that body is the entire text with URLs.
def bitly_body(body)
matches = body.scan(/((http|https):\/\/(\&|\=|\_|\?|\w|\.|\d|\/|-)+(:\d+(\&|\=|\?|\w|\.|\d|\/|-)+)?)/)
Bitly.use_api_version_3
bitly = Bitly.new("thealey", "bitly_api_key")
(0..matches.length).each do |i| # <-- changed here.
if matches[i].to_s.size > 0
logger.info("url " + matches[i][0])
if matches[i][0].include? "bit.ly"
logger.info("already a bitly url " + matches[i][0])
else
u = bitly.shorten(matches[i][0])
body[matches[i][0]] = u.short_url
end
end
end
body
end