比方說,使用陣列的delete_if命令
script = Array.new
script.push("/home/dexter/constant.sh")
script.push("/home/dexter/constant_validation.rb")
script.push("/home/dexter/jobs/reporter.rb")
現在,當我使用陣列的方法delete_if,
script.compact.delete_if {|s| s =~ /constant/}
這應該刪除從陣列含有 「恆定」 的元素。這是我在交互式ruby下執行它時得到的輸出。
puts script => ["/home/dexter/jobs/reporter.rb"]
我正通過正則表達式匹配將元素推入數組中。
任何想法我做錯了什麼?
乾杯。
當你把它放在腳本中時你會得到什麼結果? – Achrome
@AshwinMukhija放入代碼時,delete_if似乎無效。在腳本數組上運行delete_if後,我得到 'puts script => [「/home/dexter/constant.sh","/home/dexter/constant_validation.rb","/home/dexter/jobs/reporter.rb 「]' – D3XT3R