Skip to content

The Enumerable mixin provides collection classes with several traversal and searching methods, and with the ability to sort. The class must provide a method each, which yields successive members of the collection. If #max, min, or sort is used, the objects in the collection must also implement a meaningful <=> operator, as these methods rely on …

Notifications You must be signed in to change notification settings

collinsugwu/Microverse201-Enumerable-Methods

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

31 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Contributors Forks Stargazers Issues MIT License


Logo

Custom Ruby Enumerables

A custom version of Ruby's enumerable methods
Explore the docs �

AssigmentReport BugRequest Feature

Table of Contents

About The Project

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.

Built With

This progam was made using this technologies

Getting Started

To get a local copy up and running follow these simple example steps.

Prerequisites

  • Ruby You can easily install Ruby on your Linux computer by using Homebrew and Chruby
brew install chruby
brew install ruby-install
ruby-install ruby

Installation

  1. Clone the repo
git clone https://github.com/collinsugwu/Microverse201-Enumerable-Methods.git

Usage

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

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

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.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Project Link: https://github.com/collinsugwu/Microverse201-Enumerable-Methods

Acknowledgements

About

The Enumerable mixin provides collection classes with several traversal and searching methods, and with the ability to sort. The class must provide a method each, which yields successive members of the collection. If #max, min, or sort is used, the objects in the collection must also implement a meaningful <=> operator, as these methods rely on …

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages