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/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")