我有一系列网址,我试图删除符合我规范的网址。
"https://blue.color.redmine.ca/groups"
我尝试从数组中删除array.delete("https://blue.color.redmine.ca/groups")
# => ["#i-", "www", "", "iPwx", "wbi", "", "wwwbk", "", "wwwf", "wwwii-w"]
:
delete
delete_if
似乎单独定位字符而不是匹配整个字符串。我还尝试使用reject!
和merge
,这似乎不会产生任何结果或破坏代码。
答案 0 :(得分:1)
该代码适用于我:
2.1.5 :001 > array = ["http://www.redmine.ca/", "http://red.redmine.ca", "https://black.redmine.ca/Pages/welcome.aspx", "http://webmail.redmine.ca", "https://blue.color.redmine.ca/groups"]
=> ["http://www.redmine.ca/", "http://red.redmine.ca", "https://black.redmine.ca/Pages/welcome.aspx", "http://webmail.redmine.ca", "https://blue.color.redmine.ca/groups"]
2.1.5 :002 > array.delete("https://blue.color.redmine.ca/groups")
=> "https://blue.color.redmine.ca/groups"
2.1.5 :003 > array
=> ["http://www.redmine.ca/", "http://red.redmine.ca", "https://black.redmine.ca/Pages/welcome.aspx", "http://webmail.redmine.ca"]
你必须在其他地方遇到问题。
答案 1 :(得分:-1)
解决方案更简单。尝试:
array -= ["https://blue.color.redmine.ca/groups"]
祝你好运;)