From 5a3a63bedf3c78587488b91533ed9e9dc4d830c5 Mon Sep 17 00:00:00 2001 From: Mwapsam Date: Thu, 31 Mar 2022 19:29:07 +0200 Subject: [PATCH 1/2] complete code --- .github/workflows/linters.yml | 20 ++++++++++++++ .github/workflows/tests.yml | 19 +++++++++++++ .rubocop.yml | 52 +++++++++++++++++++++++++++++++++++ Gemfile | 4 +++ Gemfile.lock | 32 +++++++++++++++++++++ my_enumerable.rb | 25 +++++++++++++++++ mylist.rb | 24 ++++++++++++++++ 7 files changed, 176 insertions(+) create mode 100644 .github/workflows/linters.yml create mode 100644 .github/workflows/tests.yml create mode 100644 .rubocop.yml create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100644 my_enumerable.rb create mode 100644 mylist.rb diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml new file mode 100644 index 0000000..0e5efbd --- /dev/null +++ b/.github/workflows/linters.yml @@ -0,0 +1,20 @@ +name: Linters + +on: pull_request + +jobs: + rubocop: + name: Rubocop + runs-on: ubuntu-18.04 + + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-ruby@v1 + with: + ruby-version: ">=3.0.x" + - name: Setup Rubocop + run: | + gem install --no-document rubocop -v '>= 1.0, < 2.0' # https://docs.rubocop.org/en/stable/installation/ + [ -f .rubocop.yml ] || wget https://raw.githubusercontent.com/microverseinc/linters-config/master/ruby/.rubocop.yml + - name: Rubocop Report + run: rubocop --color \ No newline at end of file diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..7401a9e --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,19 @@ +name: Tests + +on: pull_request + +jobs: + rspec: + name: RSpec + runs-on: ubuntu-18.04 + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-ruby@v1 + with: + ruby-version: 3.0.x + - name: Setup RSpec + run: | + [ -f Gemfile ] && bundle + gem install --no-document rspec -v '>=3.0, < 4.0' + - name: RSpec Report + run: rspec --force-color --format documentation \ No newline at end of file diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..4948d48 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,52 @@ +AllCops: + NewCops: enable + Exclude: + - "Guardfile" + - "Rakefile" + - "node_modules/**/*" + + DisplayCopNames: true + +Layout/LineLength: + Max: 120 +Metrics/MethodLength: + Max: 20 +Metrics/AbcSize: + Max: 50 +Metrics/ClassLength: + Max: 150 +Metrics/BlockLength: + IgnoredMethods: ['describe'] + Max: 30 + + +Style/Documentation: + Enabled: false +Style/ClassAndModuleChildren: + Enabled: false +Style/EachForSimpleLoop: + Enabled: false +Style/AndOr: + Enabled: false +Style/DefWithParentheses: + Enabled: false +Style/FrozenStringLiteralComment: + EnforcedStyle: never + +Layout/HashAlignment: + EnforcedColonStyle: key +Layout/ExtraSpacing: + AllowForAlignment: false +Layout/MultilineMethodCallIndentation: + Enabled: true + EnforcedStyle: indented +Lint/RaiseException: + Enabled: false +Lint/StructNewOverride: + Enabled: false +Style/HashEachMethods: + Enabled: false +Style/HashTransformKeys: + Enabled: false +Style/HashTransformValues: + Enabled: false \ No newline at end of file diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..a959830 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source 'https://rubygems.org' +git_source(:github) { |repo| "https://github.com/#{repo}.git" } + +gem 'rubocop', '>= 1.0', '< 2.0' diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..ea8b773 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,32 @@ +GEM + remote: https://rubygems.org/ + specs: + ast (2.4.2) + parallel (1.22.1) + parser (3.1.1.0) + ast (~> 2.4.1) + rainbow (3.1.1) + regexp_parser (2.2.1) + rexml (3.2.5) + rubocop (1.26.1) + parallel (~> 1.10) + parser (>= 3.1.0.0) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml + rubocop-ast (>= 1.16.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.16.0) + parser (>= 3.1.1.0) + ruby-progressbar (1.11.0) + unicode-display_width (2.1.0) + +PLATFORMS + x64-mingw-ucrt + +DEPENDENCIES + rubocop (>= 1.0, < 2.0) + +BUNDLED WITH + 2.3.10 diff --git a/my_enumerable.rb b/my_enumerable.rb new file mode 100644 index 0000000..5bacc8e --- /dev/null +++ b/my_enumerable.rb @@ -0,0 +1,25 @@ +module MyEnumerable + # The method returns true if the block never returns false or nil. + def all? + each do |e| + return false unless yield e + end + true + end + + def any? + each do |e| + return true if yield e + end + false + end + + # Returns an array containing all elements of enum for which the given block returns a true value. + def filter + result = [] + each do |e| + result.push(e) if yield e + end + result + end +end diff --git a/mylist.rb b/mylist.rb new file mode 100644 index 0000000..5b4dff6 --- /dev/null +++ b/mylist.rb @@ -0,0 +1,24 @@ +require_relative './my_enumerable' +class MyList + include MyEnumerable + + def initialize(*list) + @list = list + end + + def each(&block) + @list.each(&block) + end +end + +list = MyList.new(1, 2, 3, 4) + +puts(list.all? { |e| e < 5 }) + +puts(list.all? { |e| e > 5 }) + +puts(list.any? { |e| e == 2 }) + +puts(list.any? { |e| e == 5 }) + +print(list.filter(&:even?)) From 697b1d539aa7ff6bc7d0fa592ec85f9a9374a989 Mon Sep 17 00:00:00 2001 From: Samuel Mwape <43408618+Mwapsam@users.noreply.github.com> Date: Thu, 31 Mar 2022 19:49:21 +0200 Subject: [PATCH 2/2] Update README.md --- README.md | 51 +++++++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index 31f44b7..6179e11 100644 --- a/README.md +++ b/README.md @@ -1,62 +1,53 @@ ![](https://img.shields.io/badge/Microverse-blueviolet) -# Project Name +# Enumerable -> Description the project. +> In this project we learnt how to use a module inside the class. We created a class MyList and a module MyEnumerable. The module MyEnumerable implements a subset of the functionality of Enumerable. ## Built With -- Major languages +- Ruby - Frameworks -- Technologies used - -## Live Demo (if available) - -[Live Demo Link](https://livedemo.com) +- Git, VScode & Ubuntu terminal ## Getting Started -**This is an example of how you may give instructions on setting up your project locally.** -**Modify this file to match your project, remove sections that don't apply. For example: delete the testing section if the currect project doesn't require testing.** - - To get a local copy up and running follow these simple example steps. ### Prerequisites +- Ensure that Ruby is installed on your machine. You can download it [here](https://www.ruby-lang.org/en/downloads/releases/). ### Setup +**Type the following commands in your terminal** -### Install - -### Usage - -### Run tests - -### Deployment - - +``` + git clone https://github.com/Mwapsam/Enumerable.git + cd Enumerable + bundle install + ruby mylist.rb + ``` ## Authors -👤 **Author1** +👤 **Mwape** -- GitHub: [@githubhandle](https://github.com/githubhandle) -- Twitter: [@twitterhandle](https://twitter.com/twitterhandle) -- LinkedIn: [LinkedIn](https://linkedin.com/in/linkedinhandle) +- GitHub: [@mwapsam](https://github.com/Mwapsam) +- Twitter: [@mwapesamuel4](https://twitter.com/mwapesamuel4) +- LinkedIn: [mwapsam](https://www.linkedin.com/in/mwapsam/) -👤 **Author2** +👤 **Alick** -- GitHub: [@githubhandle](https://github.com/githubhandle) -- Twitter: [@twitterhandle](https://twitter.com/twitterhandle) -- LinkedIn: [LinkedIn](https://linkedin.com/in/linkedinhandle) +- GitHub: [@alicknyerende](https://github.com/Beardless-sheik) +- Twitter: [@beardless_sheik](https://twitter.com/Beardless_Sheik) +- LinkedIn: [Alick Nyirenda](https://www.linkedin.com/in/alick-nyirenda/) ## 🤝 Contributing Contributions, issues, and feature requests are welcome! -Feel free to check the [issues page](../../issues/). +Feel free to check the [issues page](https://github.com/Mwapsam/Enumerable/issues/). ## Show your support