summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--io.c1
-rw-r--r--spec/ruby/core/io/ungetc_spec.rb17
2 files changed, 13 insertions, 5 deletions
diff --git a/io.c b/io.c
index 03209f752b..9634e2c57d 100644
--- a/io.c
+++ b/io.c
@@ -4350,7 +4350,6 @@ rb_io_ungetc(VALUE io, VALUE c)
GetOpenFile(io, fptr);
rb_io_check_char_readable(fptr);
- if (NIL_P(c)) return Qnil;
if (FIXNUM_P(c)) {
c = rb_enc_uint_chr(FIX2UINT(c), io_read_encoding(fptr));
}
diff --git a/spec/ruby/core/io/ungetc_spec.rb b/spec/ruby/core/io/ungetc_spec.rb
index 34d4caf745..4be0e3aa8b 100644
--- a/spec/ruby/core/io/ungetc_spec.rb
+++ b/spec/ruby/core/io/ungetc_spec.rb
@@ -103,10 +103,19 @@ describe "IO#ungetc" do
-> { @io.sysread(1) }.should raise_error(IOError)
end
- it "does not affect the stream and returns nil when passed nil" do
- @io.getc.should == ?V
- @io.ungetc(nil)
- @io.getc.should == ?o
+ ruby_version_is "0"..."2.8" do
+ it "does not affect the stream and returns nil when passed nil" do
+ @io.getc.should == ?V
+ @io.ungetc(nil)
+ @io.getc.should == ?o
+ end
+ end
+
+ ruby_version_is "2.8" do
+ it "raises TypeError if passed nil" do
+ @io.getc.should == ?V
+ proc{@io.ungetc(nil)}.should raise_error(TypeError)
+ end
end
it "puts one or more characters back in the stream" do