Skip to content

Commit 78772b4

Browse files
committed
Include MyEnumerable inside MyList class and print the test cases.
1 parent 11efa2c commit 78772b4

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

my_list.rb

+19-4
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,26 @@
33
class MyList
44
include MyEnumerable
55

6-
def initialize(items)
7-
@items = items
6+
attr_reader :list
7+
8+
def initialize(*items)
9+
@list = items
810
end
911

10-
def each
11-
# Implementation of each method
12+
def each(&block)
13+
@list.each(&block)
1214
end
1315
end
16+
17+
list = MyList.new(1, 2, 3, 4, 5)
18+
19+
puts(list.all? { |x| x < 6 })
20+
# true
21+
puts(list.all? { |e| e > 5 })
22+
# false
23+
puts(list.any? { |e| e == 2 })
24+
# true
25+
puts(list.any? { |e| e == 6 })
26+
# false
27+
print(list.filter(&:even?))
28+
# [2, 4]

0 commit comments

Comments
 (0)