[2017][ruby][16.x] use StringScanner better

sorbet
Alpha Chen 7 years ago
parent 608047c8bf
commit 2fb5e076e0

@ -7,18 +7,13 @@ def run
ss = StringScanner.new(@dance) ss = StringScanner.new(@dance)
until ss.eos? until ss.eos?
case case
when ss.scan(/s/) when ss.scan(/s(\d+)/)
spin = ss.scan(/\d+/).to_i @programs.rotate!(@programs.size - ss[1].to_i)
@programs.rotate!(@programs.size - spin) when ss.scan(/x(\d+)\/(\d+)/)
when ss.scan(/x/) a, b = ss[1].to_i, ss[2].to_i
a = ss.scan(/\d+/).to_i
ss.scan(/\//)
b = ss.scan(/\d+/).to_i
@programs[a], @programs[b] = @programs[b], @programs[a] @programs[a], @programs[b] = @programs[b], @programs[a]
when ss.scan(/p/) when ss.scan(/p(\w)\/(\w)/)
a = @programs.index(ss.scan(/\w/)) a, b = @programs.index(ss[1]), @programs.index(ss[2])
ss.scan(/\//)
b = @programs.index(ss.scan(/\w/))
@programs[a], @programs[b] = @programs[b], @programs[a] @programs[a], @programs[b] = @programs[b], @programs[a]
when ss.scan(/,/) when ss.scan(/,/)
end end

Loading…
Cancel
Save