block_scanf

block_scanf(fstr)
Instance Public methods

Scans the current string until the match is exhausted yielding each match as it is encountered in the string. A block is not necessary as the results will simply be aggregated into the final array.

"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 #block_scanf

doc_ruby_on_rails
2015-05-15 14:04:13
Comments
Leave a Comment

Please login to continue.