Project

General

Profile

Actions

Bug #701

closed

Wrong behaviour of StringIO#ungetc

Added by eao197 (Yauheni Akhotnikau) about 16 years ago. Updated over 13 years ago.

Status:
Closed
Assignee:
-
ruby -v:
Backport:
[ruby-core:19632]

Description

=begin
This is the behaviour of StringIO#ungetc from Ruby 1.8.7:

irb(main):001:0> require 'stringio'
=> true
irb(main):002:0> a=StringIO.new('abcd')
=> #StringIO:0x2ba7e24
irb(main):003:0> a.getc;a.getc;a.getc;a.tell # Read 'a','b','c'. Current position is on 'd'.
=> 3
irb(main):004:0> a.ungetc(?#)
=> nil
irb(main):005:0> a.tell
=> 2
irb(main):006:0> a.string
=> "ab#d"
irb(main):007:0>

And this is from Ruby 1.9.1 (Win32 version):

irb(main):001:0> require 'stringio'
=> true
irb(main):002:0> a=StringIO.new('abcd')
=> #StringIO:0xe0388c
irb(main):003:0> a.getc; a.getc; a.getc; a.tell
=> 3
irb(main):004:0> a.ungetc('#')
=> nil
irb(main):005:0> a.tell
=> 1
irb(main):006:0> a.string
=> "a#cd"

a.ungetc should replace 'c' to '#', but not 'b'.
=end

Actions

Also available in: Atom PDF

Like0
Like0