/our-enumerable

In this project you will learn how to use a module inside your class.

Primary LanguageRubyMIT LicenseMIT

logo

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

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

  • Key Features

    • 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 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.

(back to top)

💻 Getting Started

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 and follow the steps described for your system to install git.
    • Also you must have Ruby installed, you can go to the Installing Ruby documentation and follow the steps for your computer OS.
  • Setup

    Clone this repository to your desired folder:

    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

    ruby my_list.rb
  • Test

    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]

(back to top)

👥 Author(s)

👨‍💻 Luis Zubia


👤 Misal Azeem

(back to top)

🔭 Future Features

  • Add methods for more than one file.
  • Use of yield in complex implementions.

(back to top)

🤝 Contributing

Contributions, issues, typos, and feature requests are welcome!

Feel free to check the issues page.

(back to top)

⭐️ Show your support

If you like this project, your support giving a ⭐ will be highly appreciated.

(back to top)

🙏 Acknowledgments

  • We would like to thank all those people that have helped us to be good programmers.

(back to top)

📝 License

This project is MIT licensed.

(back to top)