In this short project, I created my own versions of the following Enumerable methods with a "my_" prefix:
- each
- each_with_index
- select
- all?
- any?
- none?
- count
- map
- inject
Made use of conditionals, loops, enums, blocks, yield and procs.
- Ruby
This code can be deployed on any Ruby IDE or code editor by cloning the repository from this link
After cloning it:
- Open the my_enumerables.rb file and see which methods are available.
- Find the original methods in Ruby Docs page. Take note of the use cases for each method. You can use them in step 4.
- Create a test.rb file to test the methods and see if they return the same output as their original Ruby Enumerable counterparts. Add "require_relative 'my_enumerables'" and "include Enumerable" as the first two lines.
- Use the test cases for each of the original methods(from step 2) to test and compare the output with their "my_" prefixed versions. They should return the same value.
- If they don't, please feel free to open an issue and let me know about them.
Repl.it Demo Link. Navigate to the my_enumerables.rb file to see what methods are available. Then go to the main.rb file, uncomment/add a test case and cick the "run" button to test the method.
👤 Abdullah Numan
- Github: @anewman15
- Twitter: @aanuman15
- Linkedin: aanuman15
Contributions, issues and feature requests are welcome! Feel free to check the issues page.
Give a ⭐️ if you like this project!