Skip to content
instance method

StringScanner#pos=

(::Integer) -> ::Integer
pos=(p1)

call-seq: pos = n -> n pointer = n -> n

Sets the byte position and the character position; returns n.

Does not affect match values.

For non-negative n, sets the position to n:

Example
scanner = StringScanner.new(HIRAGANA_TEXT)
scanner.string  # => "こんにちは"
scanner.pos = 3 # => 3
scanner.rest    # => "んにちは"
scanner.charpos # => 1

For negative n, counts from the end of the stored string:

Example
scanner.pos = -9 # => -9
scanner.pos      # => 6
scanner.rest     # => "にちは"
scanner.charpos  # => 2
See also #pos #post_match #pointer= #pre_match also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0