scan

scan(pattern) => String
Instance Public methods

Tries to match with pattern at the current position. If there's a match, the scanner advances the Ă¢scan pointerĂ¢ and returns the matched string. Otherwise, the scanner returns nil.

s = StringScanner.new('test string')
p s.scan(/\w+/)   # -> "test"
p s.scan(/\w+/)   # -> nil
p s.scan(/\s+/)   # -> " "
p s.scan(/\w+/)   # -> "string"
p s.scan(/./)     # -> nil
doc_ruby_on_rails
2015-05-16 04:08:46
Comments
Leave a Comment

Please login to continue.