diff --git a/src/digest/io_digest.cr b/src/digest/io_digest.cr index 6789513cc847..0efcb56b7715 100644 --- a/src/digest/io_digest.cr +++ b/src/digest/io_digest.cr @@ -31,7 +31,7 @@ class IO::Digest < IO end def read(slice : Bytes) : Int32 - read_bytes = io.read(slice) + read_bytes = io.read(slice).to_i32 if @mode.read? digest_algorithm.update(slice[0, read_bytes]) end diff --git a/src/enumerable.cr b/src/enumerable.cr index 130f926a2829..b9c3f587cfea 100644 --- a/src/enumerable.cr +++ b/src/enumerable.cr @@ -238,7 +238,7 @@ module Enumerable(T) # ``` # [1, 2, 3, 4].count { |i| i % 2 == 0 } # => 2 # ``` - def count + def count(& : T -> _) : Int32 count = 0 each { |e| count += 1 if yield e } count @@ -624,7 +624,7 @@ module Enumerable(T) # ``` # # Returns `nil` if the block didn't return `true` for any element. - def index + def index(& : T -> _) : Int32? each_with_index do |e, i| return i if yield e end @@ -638,7 +638,7 @@ module Enumerable(T) # ``` # # Returns `nil` if *obj* is not in the collection. - def index(obj) + def index(obj) : Int32? index { |e| e == obj } end diff --git a/src/http/content.cr b/src/http/content.cr index ec7fe2bb252c..9bec0e66abda 100644 --- a/src/http/content.cr +++ b/src/http/content.cr @@ -60,7 +60,7 @@ module HTTP def read(slice : Bytes) : Int32 ensure_send_continue - @io.read(slice) + @io.read(slice).to_i32 end def read_byte : UInt8? @@ -73,7 +73,7 @@ module HTTP @io.peek end - def skip(bytes_count) : Int32? + def skip(bytes_count) : Nil ensure_send_continue @io.skip(bytes_count) end @@ -123,7 +123,7 @@ module HTTP to_read = Math.min(count, @chunk_remaining) - bytes_read = @io.read slice[0, to_read] + bytes_read = @io.read(slice[0, to_read]).to_i32 if bytes_read == 0 raise IO::EOFError.new("Invalid HTTP chunked content") @@ -164,7 +164,7 @@ module HTTP peek end - def skip(bytes_count) : Int32? + def skip(bytes_count) : Nil ensure_send_continue if bytes_count <= @chunk_remaining @io.skip(bytes_count) diff --git a/src/humanize.cr b/src/humanize.cr index 251d1f563eb8..b7326b5076fc 100644 --- a/src/humanize.cr +++ b/src/humanize.cr @@ -82,7 +82,7 @@ struct Number end # :nodoc: - def self.prefix_index(i, group = 3) : Int32 + def self.prefix_index(i : Int32, group : Int32 = 3) : Int32 ((i - (i > 0 ? 1 : 0)) // group) * group end diff --git a/src/io/hexdump.cr b/src/io/hexdump.cr index b48d36ac8bfa..1ead92779cc0 100644 --- a/src/io/hexdump.cr +++ b/src/io/hexdump.cr @@ -26,8 +26,8 @@ class IO::Hexdump < IO def initialize(@io : IO, @output : IO = STDERR, @read = false, @write = false) end - def read(buf : Bytes) - @io.read(buf).tap do |read_bytes| + def read(buf : Bytes) : Int32 + @io.read(buf).to_i32.tap do |read_bytes| buf[0, read_bytes].hexdump(@output) if @read && read_bytes end end diff --git a/src/io/memory.cr b/src/io/memory.cr index 2d3dbb5256ac..20e4ec0865c9 100644 --- a/src/io/memory.cr +++ b/src/io/memory.cr @@ -192,7 +192,7 @@ class IO::Memory < IO end # :nodoc: - def skip(bytes_count) + def skip(bytes_count) : Nil check_open available = @bytesize - @pos diff --git a/src/io/sized.cr b/src/io/sized.cr index 7c26b20319fa..ad451523fffe 100644 --- a/src/io/sized.cr +++ b/src/io/sized.cr @@ -29,7 +29,7 @@ class IO::Sized < IO check_open count = {slice.size.to_u64, @read_remaining}.min - bytes_read = @io.read slice[0, count] + bytes_read = @io.read(slice[0, count]).to_i32 @read_remaining -= bytes_read bytes_read end diff --git a/src/io/stapled.cr b/src/io/stapled.cr index f236baf0ec76..98d90eadb238 100644 --- a/src/io/stapled.cr +++ b/src/io/stapled.cr @@ -33,7 +33,7 @@ class IO::Stapled < IO def read(slice : Bytes) : Int32 check_open - @reader.read(slice) + @reader.read(slice).to_i32 end # Gets a string from `reader`. diff --git a/src/string.cr b/src/string.cr index 953381d05221..a6c22706344c 100644 --- a/src/string.cr +++ b/src/string.cr @@ -817,7 +817,7 @@ class String # s[-2..-4] # => "" # s[-2..1] # => "" # s[3..-4] # => "" - # ``` : String + # ``` def [](range : Range) : String self[*Indexable.range_to_index_and_count(range, size) || raise IndexError.new] end @@ -5010,7 +5010,7 @@ class String # Raises an `ArgumentError` if `self` has null bytes. Returns `self` otherwise. # # This method should sometimes be called before passing a `String` to a C function. - def check_no_null_byte(name = nil) : String + def check_no_null_byte(name = nil) : self if byte_index(0) name = "`#{name}` " if name raise ArgumentError.new("String #{name}contains null byte")