https://github.com/luigirazum/our-enumerable
In this project you will learn how to use a module inside your class.
https://github.com/luigirazum/our-enumerable
Last synced: 5 months ago
JSON representation
In this project you will learn how to use a module inside your class.
- Host: GitHub
- URL: https://github.com/luigirazum/our-enumerable
- Owner: luigirazum
- License: mit
- Created: 2023-07-20T12:06:03.000Z (about 2 years ago)
- Default Branch: dev
- Last Pushed: 2023-07-20T14:47:44.000Z (about 2 years ago)
- Last Synced: 2024-04-15T01:57:03.973Z (over 1 year ago)
- Language: Ruby
- Size: 34.2 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![]()
### My Enumerable
In this project you will learn how to use a module inside a class. Also you will learn how to use `yield` to run a block received by a method where it is used, returning the value of the block.# 📗 Table of Contents
- [📨 My Enumerable](#about-project)
- [🛠 Built With](#built-with)
- [Tech Stack](#tech-stack)
- [Key Features](#key-features)
- [💻 Getting Started](#getting-started)
- [Prerequisites](#prerequisites)
- [Setup](#setup)
- [Run](#run)
- [👥 Authors](#authors)
- [🔭 Future Features](#future-features)
- [🤝 Contributing](#contributing)
- [⭐️ Show your support](#support)
- [🙏 Acknowledgements](#acknowledgements)
- [📝 License](#license)In this project you will learn how to use a module inside a class. Also you will learn how to use `yield` to run a block received by a method where it is used, returning the value of the block.
## 🛠 Built With
- #### 1️⃣ Create a class named `MyList`.
- It has a `@list` instance variable.
- It implements a method called `each` that yields successive members of `@list` and uses a module named `MyEnumerable`.
- #### 2️⃣ Create a module named `MyEnumerable`.
- It implements `all?`, `any?` and `filter` methods.
- These methods should have the same funcionality as methods in [Enumerable](https://ruby-doc.org/core-3.0.0/Enumerable.html) class.
- #### 2️⃣ Each class and module should has a separate `.rb` file.
- `MyEnumerable` module is used in the `MyList` class.
- Reuse code from different files.
To get a local copy of this project up and running, follow these steps.
- ### Prerequisites
- In order to run this project locally you need `git` installed. Please got to [Getting Started - Installing Git guide](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) and follow the steps described for your system to install `git`.
- Also you must have `Ruby` installed, you can go to the [Installing Ruby](https://www.ruby-lang.org/en/documentation/installation/) documentation and follow the steps for your computer OS.
- ### Setup
Clone this repository to your desired folder:
```sh
cd my-folder
git clone git@github.com:luigirazum/our-enumerable.git
cd our-enumerable
```
- ### Run
In the `our-enumerable` folder, use the following code to run the app
```rb
ruby my_list.rb
```
- ### Test
In the `irb` shell, use the following to test the code
```rb
# Import MyList class
irb> require_relative 'my_list'
=> true
# Create our list
irb> list = MyList.new(1, 2, 3, 4)
=> #
# Test #all?
irb> list.all? {|e| e < 5}
=> true
irb> list.all? {|e| e > 5}
=> false
# Test #any?
irb> list.any? {|e| e == 2}
=> true
irb> list.any? {|e| e == 5}
=> false
# Test #filter
irb> list.filter {|e| e.even?}
=> [2, 4]
```
👨💻 **Luis Zubia**
👤 **Misal Azeem**
- Add methods for more than one file.
- Use of `yield` in complex implementions.
Contributions, issues, typos, and feature requests are welcome!
Feel free to check the [issues page](../../issues/).
If you like this project, your support giving a ⭐ will be highly appreciated.
- We would like to thank all those people that have helped us to be good programmers.
This project is [MIT](./LICENSE) licensed.