A custom version of Ruby's enumerable methods
Explore the docs �
Assigment
�
Report Bug
�
Request Feature
The Enumerable mixin provides collection classes with several traversal and searching methods, and with the ability to sort. The class must provide a method my_each, which yields successive members of the collection. If Enumerable#max, #min, or #sort is used, the objects in the collection must also implement a meaningful <=> operator, as these methods rely on an ordering between members of the collection.
This progam was made using this technologies
To get a local copy up and running follow these simple example steps.
brew install chruby
brew install ruby-install
ruby-install ruby
- Clone the repo
git clone https://github.com/collinsugwu/Microverse201-Enumerable-Methods.git
Every enumerable method uses the custom my_each method to iterate through a Hash or an array.
def my_each
return to_enum(:my_each) unless block_given?
new_array = is_a?(Range) ? to_a : self
i = 0
while i < new_array.size
yield new_array[i]
i += 1
end
self
end
Each method can use the custom my_each this way.
def my_select
return to_enum(:my_select) unless block_given?
result = []
if block_given?
my_each { |i| result << i if yield(i) }
end
result
end
Run Test
rspec
See the open issues for a list of proposed features (and known issues).
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Project Link: https://github.com/collinsugwu/Microverse201-Enumerable-Methods