"123 456".block_scanf("%d") # => [123, 456]
If a block is given, the value from that is returned from the yield is added to an output array.
"123 456".block_scanf("%d) do |digit,| # the ',' unpacks the Array digit + 100 end # => [223, 556]
See Scanf for details on creating a format string.
You will need to require ‘scanf’ to use String#block_scanf
# File lib/scanf.rb, line 748 def block_scanf(fstr,&b) #:yield: current_match fs = Scanf::FormatString.new(fstr) str = self.dup final =  begin current = str.scanf(fs) final.push(yield(current)) unless current.empty? str = fs.string_left end until current.empty? || str.empty? return final end