I guess the array subtraction is more applicable here since it’s self-descriptive for future code revisions (you are indeed willing to subtract unnecessary items from an array, aren’t you?)
order_items - uri.map { |e| e.gsub /\D/, '' }
UPD Ooups… Benchmarking forces me to think accurately, for given example it came to:
order_items - uri.map { |i| i[24..27] }
Benchmarking:
order_items=["2832","3284","9832","9234"]
uri=["orderaccept/order_items/3284/cancel","orderaccept/order_items/9234/cancel"]
require 'benchmark'
n = 1_000_000
Benchmark.bm do |x|
x.report("select:") { n.times do order_items.select{|i| !uri.join.include? i}; end }
x.report("reject:") { n.times do order_items.reject{|i| uri.join.include? i}; end }
x.report("none?:") { n.times do order_items.select { |item| uri.none? { |u| u.include?(item) } }; end }
x.report("subt+gsub:") { n.times do order_items - uri.map { |e| e.gsub /\D/, '' }; end }
x.report("subt+substr:") {n.times do order_items - uri.map { |i| i[24..27] }; end }
end
Yielding:
user system total real
select: 7.200000 0.000000 7.200000 ( 7.206846)
reject: 6.240000 0.000000 6.240000 ( 6.253924)
none?: 9.230000 0.020000 9.250000 ( 9.282425)
subt+gsub: 43.440000 0.000000 43.440000 ( 43.491133)
subt+substr: 5.320000 0.010000 5.330000 ( 5.333616)