ruby – URI提取以冒号逃逸,以任何方式避免这种情况?

ruby – URI提取以冒号逃逸,以任何方式避免这种情况?,第1张

概述我在下面有以下功能,通常会吐出一个URL,例如path.com/p/12345. 有时,当推文在推文之前包含冒号时,例如 RT: Something path.com/p/123 该函数将返回: personName:path.com/p/12345 我的功能: $a = 10def grabTweets() tweet = Twitter.search("[pic] "+" path. 我在下面有以下功能,通常会吐出一个URL,例如path.com/p/12345.

有时,当推文在推文之前包含冒号时,例如

RT: Something path.com/p/123

该函数将返回:

personname:path.com/p/12345

我的功能:

$a = 10def grabTweets()  tweet = Twitter.search("[pic] "+" path.com/p/",:rpp => $a,:result_type => "recent").map do |status|    tweet = "#{status.text}" #class = string    urls = URI::extract(tweet) #returns an array of strings  endend

我的目标是在URL之前找到带冒号的任何推文,并从循环中删除该结果,以便它不会返回到创建的数组.

解决方法 您只能选择http网址:

URI.extract("RT: Something http://path.com/p/123")  # => ["RT:","http://path.com/p/123"]URI.extract("RT: Something http://path.com/p/123","http")  # => ["http://path.com/p/123"]

你的方法也可以清理很多,你有很多多余的局部变量:

def grabTweets  Twitter.search("[pic] "+" path.com/p/",:result_type => "recent").map do |status|    URI.extract(status.text,"http")  endend

我还想强烈反对使用全局变量($a).

总结

以上是内存溢出为你收集整理的ruby – URI提取以冒号逃逸,以任何方式避免这种情况?全部内容,希望文章能够帮你解决ruby – URI提取以冒号逃逸,以任何方式避免这种情况?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1274218.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存