Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -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
19 changes: 19 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -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
52 changes: 52 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

gem 'rubocop', '>= 1.0', '< 2.0'
32 changes: 32 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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
51 changes: 21 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
25 changes: 25 additions & 0 deletions my_enumerable.rb
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions mylist.rb
Original file line number Diff line number Diff line change
@@ -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?))