-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementation #1
Merged
Merged
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8a54c9a
Formatted text content
mahammad-mostafa a1e17cb
Created default dependencies
mahammad-mostafa 9980795
Included linters configurations
mahammad-mostafa 7218580
Implemented several array methods
mahammad-mostafa 189ad87
Created list class with initializer & each loop
mahammad-mostafa ae4fa8a
Documented project information
mahammad-mostafa 62864ed
Fixed word typo in features section
mahammad-mostafa 4085378
Renamed Enumerable to MyEnumerable
mahammad-mostafa 3e573a3
Used require_relative & allowed variable arguments
mahammad-mostafa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-22.04 | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-ruby@v1 | ||
with: | ||
ruby-version: ">=3.1.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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | ||
AllowedMethods: ['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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
source 'https://rubygems.org' | ||
|
||
# gem "rails" | ||
gem 'rubocop', '>= 1.0', '< 2.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
ast (2.4.2) | ||
base64 (0.1.1) | ||
json (2.6.3) | ||
language_server-protocol (3.17.0.3) | ||
parallel (1.23.0) | ||
parser (3.2.2.4) | ||
ast (~> 2.4.1) | ||
racc | ||
racc (1.7.1) | ||
rainbow (3.1.1) | ||
regexp_parser (2.8.2) | ||
rexml (3.2.6) | ||
rubocop (1.57.0) | ||
base64 (~> 0.1.1) | ||
json (~> 2.3) | ||
language_server-protocol (>= 3.17.0) | ||
parallel (~> 1.10) | ||
parser (>= 3.2.2.4) | ||
rainbow (>= 2.2.2, < 4.0) | ||
regexp_parser (>= 1.8, < 3.0) | ||
rexml (>= 3.2.5, < 4.0) | ||
rubocop-ast (>= 1.28.1, < 2.0) | ||
ruby-progressbar (~> 1.7) | ||
unicode-display_width (>= 2.4.0, < 3.0) | ||
rubocop-ast (1.29.0) | ||
parser (>= 3.2.1.0) | ||
ruby-progressbar (1.13.0) | ||
unicode-display_width (2.5.0) | ||
|
||
PLATFORMS | ||
arm64-darwin-22 | ||
|
||
DEPENDENCIES | ||
rubocop (>= 1.0, < 2.0) | ||
|
||
BUNDLED WITH | ||
2.4.10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
<a name="title"></a> | ||
|
||
<!-- TITLE --> | ||
|
||
# 🏷️ Enumerable Methods | ||
|
||
This is the fourth project of the fourth module in the **Microverse** program. | ||
<br/> | ||
Check the below contents for further details about this project. | ||
|
||
<!-- CONTENTS --> | ||
|
||
# 📗 Contents | ||
|
||
- [Description](#description) | ||
- [Instructions](#instructions) | ||
- [Authors](#authors) | ||
- [Future](#future) | ||
- [Contributions](#contributions) | ||
- [Support](#support) | ||
- [Acknowledgements](#acknowledgements) | ||
- [License](#license) | ||
|
||
<!-- DESCRIPTION --> | ||
|
||
<a name="description"></a> | ||
|
||
# 📖 Description | ||
|
||
This repository includes a class file `MyList` & a module file `MyEnumerable`. | ||
|
||
|
||
📌 **Tech Stack:** | ||
- Code built with `Ruby` | ||
|
||
📌 **Key Features:** | ||
- Class `MyList` includes a module & contains two methods | ||
- First method is to intialize the class with an array instance `list` | ||
- Second method `each` implements looping through `list` instance | ||
- Module `MyEnumerable` contains methods for several array operations | ||
- First method `all` checks if all elements of `list` array meets a comparison | ||
- Second method `any` checks if any element of `list` array meets a comparison | ||
- Third method `filter` return a new array if any element of `list` array meets a condition | ||
- Fourth method `min` returns the minimum value in `list` array | ||
- Fifth method `max` returns the maximum value in `list` array | ||
|
||
<p align="right"><a href="#title">back to top</a></p> | ||
|
||
<!-- INSTRUCTIONS --> | ||
|
||
<a name="instructions"></a> | ||
|
||
# 🛠️ Instructions | ||
|
||
You can easily download or fork this repository and work on it immadiately! | ||
|
||
📌 **Prerequisites:** | ||
- You need `Ruby` language installed | ||
|
||
📌 **Installation:** | ||
- To install all gem dependencies run | ||
``` | ||
bundle install | ||
``` | ||
|
||
📌 **Development:** | ||
- Run project with | ||
``` | ||
ruby list.rb | ||
``` | ||
|
||
<p align="right"><a href="#title">back to top</a></p> | ||
|
||
<!-- AUTHORS --> | ||
|
||
<a name="authors"></a> | ||
|
||
# 👥 Authors | ||
|
||
📌 **Mahammad:** | ||
- [GitHub](https://github.com/mahammad-mostafa) | ||
- [Twitter](https://twitter.com/mahammad_mostfa) | ||
- [LinkedIn](https://linkedin.com/in/mahammad-mostafa) | ||
|
||
📌 **Carlos:** | ||
- [GitHub](https://github.com/CarlosZ96) | ||
|
||
📌 **Austin:** | ||
- [GitHub](https://github.com/stino-x) | ||
|
||
<p align="right"><a href="#title">back to top</a></p> | ||
|
||
<!-- FUTURE --> | ||
|
||
<a name="future"></a> | ||
|
||
# 🔭 Future | ||
|
||
Some additional features I may implement in the project: | ||
- [ ] Implement Object oriented programming | ||
|
||
<p align="right"><a href="#title">back to top</a></p> | ||
|
||
<!-- CONTRIBUTIONS --> | ||
|
||
<a name="contributions"></a> | ||
|
||
# 🤝🏻 Contributions | ||
|
||
Wish to contribute to this project? | ||
<br/> | ||
Contributions, issues, and feature requests are more than welcome! | ||
<br/> | ||
Feel free to check the [issues](../../issues) page too. | ||
|
||
<p align="right"><a href="#title">back to top</a></p> | ||
|
||
<!-- SUPPORT --> | ||
|
||
<a name="support"></a> | ||
|
||
# ⭐️ Support | ||
|
||
Like this project? Show your support by starring! | ||
|
||
<p align="right"><a href="#title">back to top</a></p> | ||
|
||
<!-- ACKNOWLEDGEMENTS --> | ||
|
||
<a name="acknowledgements"></a> | ||
|
||
# 🙏🏻 Acknowledgements | ||
|
||
I thank everyone at **Microverse** for guiding me through this project. | ||
|
||
<p align="right"><a href="#title">back to top</a></p> | ||
|
||
<!-- LICENSE --> | ||
|
||
<a name="license"></a> | ||
|
||
# 📝 License | ||
|
||
This project is [MIT](LICENSE.md) licensed. | ||
|
||
<p align="right"><a href="#title">back to top</a></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module MyEnumerable | ||
def all? | ||
each { |element| return false unless yield element } | ||
true | ||
end | ||
|
||
def any? | ||
each { |element| return true if yield element } | ||
false | ||
end | ||
|
||
def filter | ||
result = [] | ||
each { |element| result.append(element) if yield element } | ||
result | ||
end | ||
|
||
def min | ||
result = nil | ||
each { |element| result = element if result.nil? || result > element } | ||
result | ||
end | ||
|
||
def max | ||
result = nil | ||
each { |element| result = element if result.nil? || result < element } | ||
result | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require './enumarable' | ||
|
||
class MyList | ||
include MyEnumerable | ||
def initialize(array) | ||
@list = array | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
def initialize(*args)
@list = []
args.each { |arg| @list << arg }
end |
||
|
||
def each | ||
counter = 0 | ||
until counter == @list.size | ||
yield @list[counter] | ||
counter += 1 | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
require_relative
to importMyEnumerable
since usingrequire_relative
for files in your directory instead ofrequire
is a ruby convention. 💯Require
should be used for external files, like gems, whilerequire_relative
should be used for referring to files within your directory."