Skip to content

Commit d92b742

Browse files
committed
Make putc signatures type-preserving overloads
Per review feedback, type `StringIO#putc` / `Zlib::GzipWriter#putc` as `(real) -> real | (String) -> String` instead of a flat `(Numeric | String) -> (Numeric | String)`. `putc` returns its argument, so the overloads preserve the caller's type; `real` is also more precise than `Numeric` since `putc` does not accept `Complex`.
1 parent 51d27db commit d92b742

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

stdlib/stringio/0/stringio.rbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,7 +1271,8 @@ class StringIO
12711271
# -->
12721272
# See IO#putc.
12731273
#
1274-
def putc: (Numeric | String arg0) -> (Numeric | String)
1274+
def putc: (real) -> real
1275+
| (String) -> String
12751276

12761277
def puts: (*untyped arg0) -> nil
12771278

stdlib/zlib/0/gzip_writer.rbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ module Zlib
125125
# -->
126126
# Same as IO.
127127
#
128-
def putc: (Numeric | String arg0) -> (Numeric | String)
128+
def putc: (real) -> real
129+
| (String) -> String
129130

130131
# <!--
131132
# rdoc-file=ext/zlib/zlib.c

0 commit comments

Comments
 (0)