Skip to content

Commit 5ddd3f7

Browse files
authored
Merge pull request #2220 from ParadoxV5/enumerator-chain
Add type for `Enumerator::Chain`
2 parents d1b2bf3 + 797fdeb commit 5ddd3f7

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

core/enumerator.rbs

+14-2
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,18 @@ end
613613
# This type of objects can be created by Enumerable#chain and Enumerator#+.
614614
#
615615
class Enumerator::Chain[out Elem] < Enumerator[Elem, void]
616-
include Enumerable[Elem]
616+
# <!--
617+
# rdoc-file=enumerator.c
618+
# - Enumerator::Chain.new(*enums) -> enum
619+
# -->
620+
# Generates a new enumerator object that iterates over the elements of given
621+
# enumerable objects in sequence.
622+
#
623+
# e = Enumerator::Chain.new(1..3, [4, 5])
624+
# e.to_a #=> [1, 2, 3, 4, 5]
625+
# e.size #=> 5
626+
#
627+
def initialize: (*_Each[Elem] enums) -> void
617628

618629
# <!--
619630
# rdoc-file=enumerator.c
@@ -626,5 +637,6 @@ class Enumerator::Chain[out Elem] < Enumerator[Elem, void]
626637
#
627638
# If no block is given, returns an enumerator.
628639
#
629-
def each: () { (Elem) -> void } -> void
640+
def each: () { (Elem) -> void } -> self
641+
| () -> Enumerator[Elem, self]
630642
end

test/stdlib/Enumerator_test.rb

+23
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,26 @@ def test_to_proc
8888
end.next
8989
end
9090
end
91+
92+
class EnumeratorChainInstanceTest < Test::Unit::TestCase
93+
include TestHelper
94+
95+
testing "::Enumerator::Chain[::Integer]"
96+
97+
def test_each
98+
enum = Enumerator::Chain.new 1..3, [4, 5]
99+
assert_send_type "() { (Integer) -> nil } -> Enumerator::Chain[Integer]",
100+
enum, :each do end
101+
end
102+
end
103+
104+
class EnumeratorChainSingletonTest < Test::Unit::TestCase
105+
include TestHelper
106+
107+
testing "singleton(::Enumerator::Chain)"
108+
109+
def test_class_new
110+
assert_send_type "(Range[Integer], Array[Integer]) -> Enumerator::Chain[Integer]",
111+
Enumerator::Chain, :new, 1..3, [4, 5]
112+
end
113+
end

0 commit comments

Comments
 (0)