V
Немножко подправил режексп
a, b = '(-8..-5)'.scan(/-?\d+/).map(&:to_i)Эдем, было бы интересно узнать ваше решение.
Size: a a a
V
a, b = '(-8..-5)'.scan(/-?\d+/).map(&:to_i)Э
Ф
Э
Ф
Э
Ф
Э
require 'benchmark'
input = '(-12, +15)'
iterations_count = 5_000_000
def split(input)
input.delete('(,)').split.map(&:to_i)
end
def scan(input)
input.scan(/-?\d+/).map(&:to_i)
end
Benchmark.bm do |x|
x.report { iterations_count.times { split(input) } }
x.report { iterations_count.times { scan(input) } }
end
user system total real
3.588879 0.000000 3.588879 ( 3.601012)
7.798909 0.000000 7.798909 ( 7.809389)
Э
Э
Э
Ф
Ф
Ф
Э
E
Ф
(n, n), тогда можно"(-1, 5)"[1..-2].split(',').map(&:to_i)
=> [-1, 5]Ф
Э