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.
- 📨 My Enumerable
- 💻 Getting Started
- 👥 Authors
- 🔭 Future Features
- 🤝 Contributing
- ⭐️ Show your support
- 🙏 Acknowledgements
- 📝 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.
-
-
- It has a
@list
instance variable. - It implements a method called
each
that yields successive members of@list
and uses a module namedMyEnumerable
.
- It has a
-
- It implements
all?
,any?
andfilter
methods. - These methods should have the same funcionality as methods in Enumerable class.
- It implements
-
MyEnumerable
module is used in theMyList
class.- Reuse code from different files.
-
To get a local copy of this project up and running, follow these steps.
-
- In order to run this project locally you need
git
installed. Please got to Getting Started - Installing Git guide and follow the steps described for your system to installgit
. - Also you must have
Ruby
installed, you can go to the Installing Ruby documentation and follow the steps for your computer OS.
- In order to run this project locally you need
-
Clone this repository to your desired folder:
cd my-folder git clone git@github.com:luigirazum/our-enumerable.git cd our-enumerable
-
In the
our-enumerable
folder, use the following code to run the appruby my_list.rb
-
In the
irb
shell, use the following to test the code# Import MyList class irb> require_relative 'my_list' => true # Create our list irb> list = MyList.new(1, 2, 3, 4) => #<MyList: @list=[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.
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 licensed.