Skip to content

Commit 535c60c

Browse files
authored
Merge pull request #1 from ab-noori/Create-Enumerable
Create Enumerable
2 parents 8a4074f + 60a9f03 commit 535c60c

File tree

8 files changed

+362
-2
lines changed

8 files changed

+362
-2
lines changed

.github/workflows/linters.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Linters
2+
3+
on: pull_request
4+
5+
jobs:
6+
rubocop:
7+
name: Rubocop
8+
runs-on: ubuntu-22.04
9+
10+
steps:
11+
- uses: actions/checkout@v3
12+
- uses: actions/setup-ruby@v1
13+
with:
14+
ruby-version: ">=3.1.x"
15+
- name: Setup Rubocop
16+
run: |
17+
gem install --no-document rubocop -v '>= 1.0, < 2.0' # https://docs.rubocop.org/en/stable/installation/
18+
[ -f .rubocop.yml ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/ruby/.rubocop.yml
19+
- name: Rubocop Report
20+
run: rubocop --color

.github/workflows/tests.yml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Tests
2+
3+
on: pull_request
4+
5+
jobs:
6+
rspec:
7+
name: RSpec
8+
runs-on: ubuntu-22.04
9+
steps:
10+
- uses: actions/checkout@v3
11+
- uses: actions/setup-ruby@v1
12+
with:
13+
ruby-version: 3.1.x
14+
- name: Setup RSpec
15+
run: |
16+
[ -f Gemfile ] && bundle
17+
gem install --no-document rspec -v '>=3.0, < 4.0'
18+
- name: RSpec Report
19+
run: rspec --force-color --format documentation

.rubocop.yml

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
AllCops:
2+
NewCops: enable
3+
Exclude:
4+
- "Guardfile"
5+
- "Rakefile"
6+
- "node_modules/**/*"
7+
8+
DisplayCopNames: true
9+
10+
Layout/LineLength:
11+
Max: 120
12+
Metrics/MethodLength:
13+
Max: 20
14+
Metrics/AbcSize:
15+
Max: 50
16+
Metrics/ClassLength:
17+
Max: 150
18+
Metrics/BlockLength:
19+
IgnoredMethods: ['describe']
20+
Max: 30
21+
22+
23+
Style/Documentation:
24+
Enabled: false
25+
Style/ClassAndModuleChildren:
26+
Enabled: false
27+
Style/EachForSimpleLoop:
28+
Enabled: false
29+
Style/AndOr:
30+
Enabled: false
31+
Style/DefWithParentheses:
32+
Enabled: false
33+
Style/FrozenStringLiteralComment:
34+
EnforcedStyle: never
35+
36+
Layout/HashAlignment:
37+
EnforcedColonStyle: key
38+
Layout/ExtraSpacing:
39+
AllowForAlignment: false
40+
Layout/MultilineMethodCallIndentation:
41+
Enabled: true
42+
EnforcedStyle: indented
43+
Lint/RaiseException:
44+
Enabled: false
45+
Lint/StructNewOverride:
46+
Enabled: false
47+
Style/HashEachMethods:
48+
Enabled: false
49+
Style/HashTransformKeys:
50+
Enabled: false
51+
Style/HashTransformValues:
52+
Enabled: false

Gemfile

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
source 'https://rubygems.org'
2+
gem 'rubocop', '>= 1.0', '< 2.0'

Gemfile.lock

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
ast (2.4.2)
5+
json (2.6.3)
6+
language_server-protocol (3.17.0.3)
7+
parallel (1.23.0)
8+
parser (3.2.2.3)
9+
ast (~> 2.4.1)
10+
racc
11+
racc (1.7.1)
12+
rainbow (3.1.1)
13+
regexp_parser (2.8.1)
14+
rexml (3.2.5)
15+
rubocop (1.54.2)
16+
json (~> 2.3)
17+
language_server-protocol (>= 3.17.0)
18+
parallel (~> 1.10)
19+
parser (>= 3.2.2.3)
20+
rainbow (>= 2.2.2, < 4.0)
21+
regexp_parser (>= 1.8, < 3.0)
22+
rexml (>= 3.2.5, < 4.0)
23+
rubocop-ast (>= 1.28.0, < 2.0)
24+
ruby-progressbar (~> 1.7)
25+
unicode-display_width (>= 2.4.0, < 3.0)
26+
rubocop-ast (1.29.0)
27+
parser (>= 3.2.1.0)
28+
ruby-progressbar (1.13.0)
29+
unicode-display_width (2.4.2)
30+
31+
PLATFORMS
32+
x64-mingw-ucrt
33+
34+
DEPENDENCIES
35+
rubocop (>= 1.0, < 2.0)
36+
37+
BUNDLED WITH
38+
2.4.17

README.md

+186-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,186 @@
1-
# Enumerable
2-
Throughout the project, the team learned how to utilize a module within a class. We designed a class called MyList and incorporated a module named MyEnumerable, which implemented a limited set of functionalities from Enumerable.
1+
<a name="readme-top"></a>
2+
3+
<!-- TABLE OF CONTENTS -->
4+
5+
# 📗 Table of Contents
6+
7+
- [📖 About the Project](#about-project)
8+
- [🛠 Built With](#built-with)
9+
- [Tech Stack](#tech-stack)
10+
- [Key Features](#key-features)
11+
- [💻 Getting Started](#getting-started)
12+
- [Setup](#setup)
13+
- [Prerequisites](#prerequisites)
14+
- [Install](#install)
15+
- [Usage](#usage)
16+
- [Run tests](#run-tests)
17+
- [Deployment](#triangular_flag_on_post-deployment)
18+
- [👥 Authors](#authors)
19+
- [🔭 Future Features](#future-features)
20+
- [🤝 Contributing](#contributing)
21+
- [⭐️ Show your support](#support)
22+
- [🙏 Acknowledgements](#acknowledgements)
23+
- [📝 License](#license)
24+
25+
<!-- PROJECT DESCRIPTION -->
26+
27+
# 📖 [Enumerable] <a name="about-project"></a>
28+
29+
> **[Enumerable]** Throughout the project, the team learned how to utilize a module within a class. We designed a class called MyList and incorporated a module named MyEnumerable, which implemented a limited set of functionalities from Enumerable.
30+
31+
## 🛠 Built With <a name="built-with"></a>
32+
33+
### Tech Stack <a name="tech-stack"></a>
34+
35+
<details>
36+
<summary>Client</summary>
37+
<ul>
38+
<li></li>
39+
</ul>
40+
</details>
41+
42+
<details>
43+
<summary>Server</summary>
44+
<ul>
45+
<li><a href="https://www.ruby-lang.org/en/">Ruby</a></li>
46+
</ul>
47+
</details>
48+
49+
<details>
50+
<summary>Database</summary>
51+
<ul>
52+
<li></li>
53+
</ul>
54+
</details>
55+
56+
<!-- Features -->
57+
58+
### Key Features <a name="key-features"></a>
59+
60+
- **[Creating module]**
61+
- **[Creating class]**
62+
- **[Including module to class]**
63+
64+
<p align="right">(<a href="#readme-top">back to top</a>)</p>
65+
66+
<!-- GETTING STARTED -->
67+
68+
## 💻 Getting Started <a name="getting-started"></a>
69+
70+
To get a local copy up and running, follow these steps.
71+
72+
### Prerequisites
73+
74+
In order to run this project you need:
75+
76+
Example command:
77+
78+
```sh
79+
Install Ruby
80+
```
81+
82+
### Setup
83+
84+
Clone this repository to your desired folder:
85+
86+
```sh
87+
cd my-folder
88+
git clone https://github.com/ab-noori/Enumerable.git
89+
```
90+
91+
### Install
92+
93+
Install this project with:
94+
95+
```sh
96+
cd my-folder
97+
git clone https://github.com/ab-noori/Enumerable.git
98+
```
99+
100+
### Usage
101+
102+
To run the project, execute the following command:
103+
104+
```sh
105+
cd my-folder
106+
git clone https://github.com/ab-noori/Enumerable.git
107+
```
108+
109+
### Run tests
110+
111+
To run tests, run the following command:
112+
113+
```sh
114+
npm test
115+
```
116+
117+
### Deployment
118+
119+
You can deploy this project using:
120+
121+
```sh
122+
npm run deploy
123+
```
124+
125+
<p align="right">(<a href="#readme-top">back to top</a>)</p>
126+
127+
<!-- AUTHORS -->
128+
129+
## 👥 Authors <a name="authors"></a>
130+
131+
👤 **Abdul Ali Noori**
132+
133+
- GitHub: [@ab-noori](https://github.com/ab-noori)
134+
- Twitter: [@AbdulAliNoori4](https://twitter.com/AbdulAliNoori4)
135+
- LinkedIn: [abdulali-noori](https://www.linkedin.com/in/abdulali-noori)
136+
137+
👤 **Otmane Echchafyky**
138+
139+
- GitHub: [@otmaneechchafyky](https://github.com/otmaneechchafyky)
140+
- Twitter: [@EchchafykyO](https://twitter.com/EchchafykyO)
141+
- LinkedIn: [otmaneechchafyky](https://www.linkedin.com/in/otmane-echchafyky-125801248/)
142+
143+
<p align="right">(<a href="#readme-top">back to top</a>)</p>
144+
145+
<!-- FUTURE FEATURES -->
146+
147+
## 🔭 Future Features <a name="future-features"></a>
148+
149+
- [ ] **[Adding more methods to the module]**
150+
- [ ] **[Creating new modules]**
151+
152+
<p align="right">(<a href="#readme-top">back to top</a>)</p>
153+
154+
<!-- CONTRIBUTING -->
155+
156+
## 🤝 Contributing <a name="contributing"></a>
157+
158+
Contributions, issues, and feature requests are welcome!
159+
160+
Feel free to check the [issues page](https://github.com/ab-noori/Enumerable/issues).
161+
162+
<p align="right">(<a href="#readme-top">back to top</a>)</p>
163+
164+
<!-- SUPPORT -->
165+
166+
## ⭐️ Show your support <a name="support"></a>
167+
168+
If you like this project, give it a star.
169+
170+
<p align="right">(<a href="#readme-top">back to top</a>)</p>
171+
172+
<!-- ACKNOWLEDGEMENTS -->
173+
174+
## 🙏 Acknowledgments <a name="acknowledgements"></a>
175+
176+
First, I would like to thank Microverse and my coding partners.
177+
178+
<p align="right">(<a href="#readme-top">back to top</a>)</p>
179+
180+
181+
## 📝 License <a name="license"></a>
182+
183+
This project is [MIT](./LICENSE) licensed.
184+
185+
<p align="right">(<a href="#readme-top">back to top</a>)</p>
186+

my_enumerable.rb

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module MyEnumerable
2+
def all?
3+
each { |item| return false unless yield(item) }
4+
true
5+
end
6+
7+
def any?
8+
each { |item| return true if yield(item) }
9+
false
10+
end
11+
12+
def filter
13+
result = []
14+
each { |item| result.push(item) if yield(item) }
15+
result
16+
end
17+
end

my_list.rb

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
require_relative 'my_enumerable'
2+
3+
class MyList
4+
include MyEnumerable
5+
6+
attr_reader :list
7+
8+
def initialize(*items)
9+
@list = items
10+
end
11+
12+
def each(&block)
13+
@list.each(&block)
14+
end
15+
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)