无法删除确切的数组项

时间:2015-10-06 21:23:25

标签: arrays ruby

我有一系列网址,我试图删除符合我规范的网址。

"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,这似乎不会产生任何结果或破坏代码。

2 个答案:

答案 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"]
祝你好运;)