Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions core/enumerable.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,11 @@
# find exactly one of each Hash entry.
#
module Enumerable[unchecked out Elem] : _Each[Elem]
%a{private}
interface _Pattern
def ===: (untyped) -> bool
end

# <!--
# rdoc-file=enum.c
# - all? -> true or false
Expand Down Expand Up @@ -234,6 +239,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
# Related: #any?, #none? #one?.
#
def all?: () -> bool
| (_Pattern) -> bool
| () { (Elem) -> boolish } -> bool

# <!--
Expand Down Expand Up @@ -277,6 +283,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
# Related: #all?, #none?, #one?.
#
def any?: () -> bool
| (_Pattern) -> bool
| () { (Elem) -> boolish } -> bool

# <!--
Expand Down Expand Up @@ -1167,6 +1174,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
# Related: #one?, #all?, #any?.
#
def none?: () -> bool
| (_Pattern) -> bool
| () { (Elem) -> boolish } -> bool

# <!--
Expand Down Expand Up @@ -1210,6 +1218,7 @@ module Enumerable[unchecked out Elem] : _Each[Elem]
# Related: #none?, #all?, #any?.
#
def one?: () -> bool
| (_Pattern) -> bool
| () { (Elem) -> boolish } -> bool

# <!--
Expand Down
24 changes: 24 additions & 0 deletions test/stdlib/Enumerable_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,4 +241,28 @@ def test_first
assert_send_type '(ToInt n) -> ::Array[::String]' , TestEnumerable.new, :first, ToInt.new(42)
assert_send_type '(ToInt n) -> ::Array[::String]' , TestEmptyEnumerable.new, :first, ToInt.new(42)
end

def test_all_p
assert_send_type '() -> bool', TestEnumerable.new, :all?
assert_send_type '(Class) -> bool', TestEnumerable.new, :all?, String
assert_send_type '() { (String) -> bool } -> bool', TestEnumerable.new, :all? do |x| x == '0' end
end

def test_any_p
assert_send_type '() -> bool', TestEnumerable.new, :any?
assert_send_type '(Class) -> bool', TestEnumerable.new, :any?, String
assert_send_type '() { (String) -> bool } -> bool', TestEnumerable.new, :any? do |x| x == '0' end
end

def test_none_p
assert_send_type '() -> bool', TestEnumerable.new, :none?
assert_send_type '(Class) -> bool', TestEnumerable.new, :none?, String
assert_send_type '() { (String) -> bool } -> bool', TestEnumerable.new, :none? do |x| x == '0' end
end

def test_one_p
assert_send_type '() -> bool', TestEnumerable.new, :one?
assert_send_type '(Class) -> bool', TestEnumerable.new, :one?, String
assert_send_type '() { (String) -> bool } -> bool', TestEnumerable.new, :one? do |x| x == '0' end
end
end