From 56736e0be43603b835c944bcfd1b3ec8d7c7e57b Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Mon, 28 Oct 2019 18:24:47 -0700 Subject: [PATCH 01/31] rubocop and stickler deleted --- .rubocop.yml | 0 .stickler.yml | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .rubocop.yml delete mode 100644 .stickler.yml diff --git a/.rubocop.yml b/.rubocop.yml deleted file mode 100644 index e69de29..0000000 diff --git a/.stickler.yml b/.stickler.yml deleted file mode 100644 index e69de29..0000000 From c5039f2cd63316251b0878def852a06158d0ee15 Mon Sep 17 00:00:00 2001 From: Kingsley McSimon O <48096869+KingsleyMcSimon@users.noreply.github.com> Date: Mon, 28 Oct 2019 10:30:20 -0700 Subject: [PATCH 02/31] Create .rubocop.yml --- .rubocop.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..c0c7636 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,33 @@ +AllCops: + Exclude: + - "db/**/*" + - "config/**/*" + - "Guardfile" + - "Rakefile" + DisplayCopNames: true + +Metrics/LineLength: + Max: 120 +Metrics/MethodLength: + Include: ["app/controllers/*"] + Max: 20 +Metrics/AbcSize: + Include: ["app/controllers/*"] + Max: 30 +Metrics/ClassLength: + Max: 150 +Metrics/BlockLength: + ExcludedMethods: ['describe'] + +Style/Documentation: + Enabled: false +Style/ClassAndModuleChildren: + Enabled: false + +Layout/AlignHash: + EnforcedColonStyle: key +Layout/ExtraSpacing: + AllowForAlignment: false +Layout/MultilineMethodCallIndentation: + Enabled: true + EnforcedStyle: indented From faa17ec424069f3b8d75379d20d862f19b53d9e2 Mon Sep 17 00:00:00 2001 From: Kingsley McSimon O <48096869+KingsleyMcSimon@users.noreply.github.com> Date: Mon, 28 Oct 2019 10:31:44 -0700 Subject: [PATCH 03/31] Create .stickler.yml --- .stickler.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .stickler.yml diff --git a/.stickler.yml b/.stickler.yml new file mode 100644 index 0000000..2a4eb06 --- /dev/null +++ b/.stickler.yml @@ -0,0 +1,10 @@ +linters: + rubocop: + display_cop_names: true +files: + ignore: + - "bin/*" + - "db/*" + - "config/*" + - "Guardfile" + - "Rakefile" From df166e075c04d07a2bb30b57649e63869842a58b Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Mon, 28 Oct 2019 21:02:24 -0700 Subject: [PATCH 04/31] Descriptive Readme --- README.md | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 76 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index f83871f..a3fff0f 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,84 @@ -# Project Descriptioon: +# Name of Project: -Advanced Building Blocks - Enumerable Methods Using Ruby Language. +Enumerable Methods + +# Table of contents: + +1. About The Project +2. Built With +3. Getting Started With The Project +4. Contributing +5. License +6. Contact/Contributors + i. Link To Project On Github +7. Acknowledgements + +# About The Project: + +Enumerable is a module in Ruby that provides many methods that can help with traversal, transforming, sorting, and filtering. Any class that can implement the #each method can use Enumerable methods, which will then yield each item in the collection to a block. + +# Built With: + +This Enumerable method project was built using the Ruby language. + +# Getting Started With The Project: + +To get started, here below are the steps that needs to be taken in order to achieve the required result from the project: + +1. Create a script file to house your methods and run it in IRB to test them later. +2. Add your new methods onto the existing Enumerable module. Ruby makes this easy for you because any class or module can be added to without trouble … just do something like: + + module Enumerable + def my_each + # your code here + end + end + +1. Create #my_each, a method that is identical to #each but (obviously) does not use #each. You’ll need to remember the yield statement. Make sure it returns the same thing as #each as well. +2. Create #my_each_with_index in the same way. +3. Create #my_select in the same way, though you may use #my_each in your definition (but not #each). +4. Create #my_all? (continue as above) +5. Create #my_any? +6. Create #my_none? +7. Create #my_count +8. Create #my_map +9. Create #my_inject +10. Test your #my_inject by creating a method called #multiply_els which multiplies all the elements of the array together by using #my_inject, e.g. multiply_els([2,4,5]) #=> 40 +11. Modify your #my_map method to take a proc instead. +12. Modify your #my_map method to take either a proc or a block. It won’t be necessary to apply both a proc and a block in the same #my_map call since you could get the same effect by chaining together one #my_map call with the block and one with the proc. This approach is also clearer, since the user doesn’t have to remember whether the proc or block will be run first. So if both a proc and a block are given, only execute the proc. + +# contributing: + +In this project, your contributions towards helping in improving this project is woild be well accomodated. With that, the project will get better rating and give programmers at any level the ability learn, be inspired and create better content. + +After you are done with your contributions, you can: + +i. Fork The project. +ii. Create your feature branch using git checkout -b feature/anyfeature(for example) +iii. Commit your changes following git commit -m 'Name it as it pleases you', when you are done, +iv. Push to the branch you have created using git push origin feature/anyfeature and finally +v. Open a pull request. + +# License: + +Distributed under the MIT Licence. See Licence for more informaton # Contributor(s): - -Kingsley McSimon Ogbonna https://github.com/KingsleyMcSimon @KingsleyMcSimon -# Link to the project on Github: +Kingsley McSimon Ogbonna @KingsleyMcSimon + +# Link To The Project On Github: https://github.com/KingsleyMcSimon/Enumerable-Methods +# Acknowledgements: + +https://medium.com/yello-offline/ruby-the-enumerable-module-under-the-hood-some-caveats-f640ce39a07d + +https://github.com/othneildrew/Best-README-Template + +https://www.theodinproject.com/courses/ruby-programming/lessons/advanced-building-blocks + + + From 88a65180dbe43d27f33b6ae1012fa51b16356bc4 Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Mon, 28 Oct 2019 21:33:42 -0700 Subject: [PATCH 05/31] Descriptive Readme Updated --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a3fff0f..bf3b241 100644 --- a/README.md +++ b/README.md @@ -11,12 +11,15 @@ Enumerable Methods 5. License 6. Contact/Contributors i. Link To Project On Github -7. Acknowledgements +7. What Was Learnt During The Project +8. Acknowledgements # About The Project: Enumerable is a module in Ruby that provides many methods that can help with traversal, transforming, sorting, and filtering. Any class that can implement the #each method can use Enumerable methods, which will then yield each item in the collection to a block. +It can also be said that "Enumerable" is actually a "module", which means it is just a bunch of methods packaged together that can (and do) get "mixed in", or included, with other classes like Array and Hash. It's designed to provide useful functionality to classes representing collections of objects. + # Built With: This Enumerable method project was built using the Ruby language. @@ -71,6 +74,10 @@ Kingsley McSimon Ogbonna @KingsleyMcSimon https://github.com/KingsleyMcSimon/Enumerable-Methods +# What Was Learnt During The Project: + +I learnt from this project that modules like Enumerable are the ultimate in DRY (Don't Repeat Yourself) code. I also understood that Ruby programmers don't have to write all those methods as mentioned above many different times - they just write them once, package them up as Enumerables and tell Array and Hash to include them. + # Acknowledgements: https://medium.com/yello-offline/ruby-the-enumerable-module-under-the-hood-some-caveats-f640ce39a07d @@ -79,6 +86,7 @@ https://github.com/othneildrew/Best-README-Template https://www.theodinproject.com/courses/ruby-programming/lessons/advanced-building-blocks +https://www.vikingcodeschool.com/falling-in-love-with-ruby/the-enumerable-module From 1cd1d608957d568416d1fbe1dddf927bc4353977 Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Mon, 28 Oct 2019 22:04:44 -0700 Subject: [PATCH 06/31] my_inject method updated --- Enumerable_Methods.rb | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index fee0ba6..83aec66 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -114,14 +114,14 @@ def my_map #my_map method mymap end - def my_map_again(myproc) #my_mapa_gain method which takes a proc + def my_map_again(myproc) #my_map_again method which takes a proc self.my_each do |b| mymapagain.push myproc.call(b) end mymapagain end - def my_map_final myproc = nil #my_map_final method which an either take a proc or a block + def my_map_final myproc = nil #my_map_final method which can either take a proc or a block mymapfinal = [] self.my_each do |b| if myproc == nil @@ -133,12 +133,13 @@ def my_map_final myproc = nil #my_map_final method which an either take a proc o mymapfinal end - def my_inject #my_inject method - output = nil - my_each = output ? yield (output, b) : self |0| + def my_inject(param = self[0]) #my_inject method + help = self + help[1..help.length].each do |b| + param = yield(param, b) end - output -end + param +end def multiply_els #multiply_els method my_inject {|mult, b | mult + b} From 32ba07bde651a3fba65fd504f5805f18369fbeb8 Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Wed, 30 Oct 2019 18:33:49 -0700 Subject: [PATCH 07/31] my_count method rewritted --- Enumerable_Methods.rb | 44 +++++++++++-------------------------------- 1 file changed, 11 insertions(+), 33 deletions(-) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index 83aec66..5824d43 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -10,9 +10,7 @@ def my_each #This is my_each method self.size.times do yield(self[a]) a += 1 - end - self end @@ -22,9 +20,7 @@ def my_each_with_index #my_each_with_index yield(self[a], a) a += 1 end - self - end def my_select #my_select method @@ -32,13 +28,9 @@ def my_select #my_select method self.my_each do |b| if yield (b) myselect.push (b) - end - end - myselect - end def my_all? #my_all method @@ -63,14 +55,12 @@ def my_any? #my_any? method if yield (b) output = true break - end - end output end - def my_none? #my_none methods + def my_none? #my_none method output = true self.my_each do |b| if yield (b) @@ -81,30 +71,18 @@ def my_none? #my_none methods output end - def my_count parameter = nil #my_count method + def my_count #my_count method mycount = 0 - self.my_each do |b| - if parameter != nil - if parameter == self[b] - mycount += 1 - end - else - if yield (b) + myhelp = self + myhelp.my_each do |a| + if block_given? + mycount += 1 if yield(a) mycount += 1 - self.my_each do |element| - if parameter - if element == parameter - mycount += 1 - end - end - elsif block_given? - mycount += if yield(element) - else - mycount = self.length - end - end - mycount - end + end + end + mycount + end + def my_map #my_map method mymap = [] From 4bc4053504fc186ae069dd01217ea25141053646 Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Mon, 4 Nov 2019 22:36:34 -0800 Subject: [PATCH 08/31] Enumerable updates --- Enumerable_Methods.rb | 57 ++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index 5824d43..e007c2b 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -5,38 +5,48 @@ module Enumerable - def my_each #This is my_each method - a = 0 - self.size.times do - yield(self[a]) - a += 1 + def my_each #my_each method + myeach = 0 + while myeach < size + yield self[myeach] + + myeach += 1 end + self end +end - def my_each_with_index #my_each_with_index - a = 0 - self.size.times do - yield(self[a], a) - a += 1 - end - self + +def my_each_with_index #my_each_with_index method + myeachwithindex = 0 + while myeachwithindex < size + yield (self[myeachwithindex], myeachwithindex) + + myeachwithindex += 1 end - def my_select #my_select method - myselect = [] - self.my_each do |b| - if yield (b) - myselect.push (b) - end + self +end +end + +def my_select #my_select method + myselect = [] + while myselect < size + if yield (b) + myselect.push (b) end myselect end +end + def my_all? #my_all method - myall = [] + myall = 0 + #myall = [] output = true - self.my_each do |b| + #self.my_each do |b| + while myall < size if yield (b) myall.push (b) end @@ -48,6 +58,7 @@ def my_all? #my_all method end output end +end def my_any? #my_any? method output = false @@ -208,3 +219,9 @@ def multiply_els #multiply_els method #puts multiply_els(arraysofnumbers) + +puts 'my_each method imp -> ' +[8, 2, 5, 4].my_each { |num| puts num } + + + From 9ed0c74e37d383795e3bd50c3b33562dfbd63837 Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Tue, 5 Nov 2019 14:49:50 -0800 Subject: [PATCH 09/31] Update in the methods --- Enumerable_Methods.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index e007c2b..0c46a67 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -25,7 +25,6 @@ def my_each_with_index #my_each_with_index method myeachwithindex += 1 end - self end end From 85c2c8da2f27f47eb77615572e17f7e01ef2c7d8 Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Tue, 5 Nov 2019 23:55:34 -0800 Subject: [PATCH 10/31] Enumerable updates --- Enumerable_Methods.rb | 149 +++++++++++++----------------------------- 1 file changed, 46 insertions(+), 103 deletions(-) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index 0c46a67..9a9f617 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -29,6 +29,7 @@ def my_each_with_index #my_each_with_index method end end + def my_select #my_select method myselect = [] while myselect < size @@ -40,47 +41,28 @@ def my_select #my_select method end - def my_all? #my_all method - myall = 0 - #myall = [] - output = true - #self.my_each do |b| - while myall < size - if yield (b) - myall.push (b) - end - end - if myall.length == self.length - output = true - else - output = false - end - output + def my_all? #my_all? method + myall = 0 + myall.my_each do |d| + return false unless yield(d) end + true end - def my_any? #my_any? method - output = false - self.my_each do |b| - if yield (b) - output = true - break - end - end - output + + def my_any #my_any method + self.my_each { |n| return true if yield (n) } end def my_none? #my_none method - output = true + mynone = true self.my_each do |b| - if yield (b) - output = false - break - end + return false if yield(b) end - output + true end + def my_count #my_count method mycount = 0 myhelp = self @@ -94,13 +76,25 @@ def my_count #my_count method end - def my_map #my_map method + def my_map(&proc) #my_map method + return self.to_enum unless block_given? + + mymap = [] - self.my_each do |b| - mymap.push yield(b) + if self.class == Hash + self.each do |a, b| + + mymap << proc.call(a, b) + end + mymap + else + self.my_each do |c| + mymap << proc.call(c) end mymap end +end +end def my_map_again(myproc) #my_map_again method which takes a proc self.my_each do |b| @@ -109,6 +103,7 @@ def my_map_again(myproc) #my_map_again method which takes a proc mymapagain end + def my_map_final myproc = nil #my_map_final method which can either take a proc or a block mymapfinal = [] self.my_each do |b| @@ -121,6 +116,8 @@ def my_map_final myproc = nil #my_map_final method which can either take a proc mymapfinal end + + def my_inject(param = self[0]) #my_inject method help = self help[1..help.length].each do |b| @@ -129,6 +126,8 @@ def my_inject(param = self[0]) #my_inject method param end + + def multiply_els #multiply_els method my_inject {|mult, b | mult + b} @@ -137,90 +136,34 @@ def multiply_els #multiply_els method - +#Here are examples that could be used to test for some of the methods above. #Testing for my_each method #(To test each of these methods, you can take it out of the comment and go ahead with the testing ) -#arraysofnumbers = [2, 4, 6, 8, 10, 12] -#arraysofnumbers.my_each do |numbers| - # numbers *= 5 - # print "#{numbers}" +#k = [1, 2, 3, 4, 5] +#k.my_each do |myeach| +#puts myeach #end #Testing for my_each_with_index method -#arraysofnumbers = [2, 4, 6, 8, 10, 12, 20, 50, 19, 25, 30, 40] -#arraysofnumbers.my_each_with_index do |value, index| -#puts "arraysofnumbers index #{index} takes the value of #{value}" +#fruits = %w(Mango Pawpaw Cashew Pear Orange) +#fruits.my_each_with_index do |myeachwithindex, idx| +#puts "#{myeachwithindex} is the fruit with index #{idx}" #end #Testing for my_select method -#arraysofnumbers = [2, 4, 6, 8, 10, 12, 20, 50, 19, 25, 30, 50] -#output = arraysofnumbers.my_select do |numbers| numbers % 2 != 0; end -#print output - -#Testing for my_all method - -#arraysofnumbers = [2, 4, 6, 8, 10, 12, 20, 50, 19, 25, 30, 40] -#output = arraysofnumbers.my_all? do |b| b % 2 == 0; end -#print output - -#Testing for my_any method - -#arraysofnumbers = [2, 4, 6, 8, 10, 12, 20, 50, 19, 25, 30, 25] -#output = arraysofnumbers.my_any? do |b| b < 3; end -#print output - -#Testing for my_none method - -#arraysofnumbers = [2, 4, 6, 8, 10, 12, 20, 50, 19, 25, 30, 10] -#output = arraysofnumbers.my_none? do |b| b % 2 == 1; end -#print output - -#Testing for my_count method - -#arraysofnumbers = [2, 5, 8, 10, 20, 15, 25, 15, 8, 4, 6] -#arraysofnumbers = [5, 8, 10, 15, 15, 8, 4, 6, 8, 2, 12, 7, 8, 10] -#output = arraysofnumbers.my_count -#output = arraysofnumbers.my_count (10) -#output = arraysofnumbers () do |numbers| numbers % 2 == 1; end -#output = arraysofnumbers (5) do |numbers|; end -#print output - -#Testing for my_map method - -#arraysofnumbers = [2, 4, 6, 8, 10, 12, 20, 50, 19, 25, 30, 20] -#output = arraysofumbers.my_map do |numbers| numbers * 2; end -#print output - -#Testing for my_map_again method (that takes a proc) - -#arraysofnumbers = [2, 4, 6, 8, 10, 12, 20, 50, 19, 25, 30, 10, 10] -#myproc = Proc.new do |numbers| numbers * 2; end -#output = arraysofnumbers.my_map_again(myproc) -#print output - -#Testing for my_map_final(3) (that takes either a proc or a block) - -#arraysofnumbers = [2, 4, 6, 8, 10, 12, 20, 50, 19, 25, 35, 30] -#myproc = Proc.new do |numbers| numbers * 2; end -#output = arraysofnumbers.my_map_final do |numbers| numbers * 3; end -#print output - -#Testing for my_inject method - -#def multiply_els(arraysofnumbers) -#arraysofnumbers.my_inject(1) do |total, numbers|total * numbers; end +#strings = %w(Angle Ball Cat Capstone Conquer) +#puts strings.my_select {|word| word.size > 3 } #end -#arraysofnumbers = [1, 4, 5, 3, 2] -#puts multiply_els(arraysofnumbers) - -puts 'my_each method imp -> ' -[8, 2, 5, 4].my_each { |num| puts num } +#To test for my_inject +#array = [1, 2, 3, 4, 5] +#array.my_inject +#end From 34c23fd56df531080d7077fc418bea5d17a852ff Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Wed, 6 Nov 2019 18:06:21 -0800 Subject: [PATCH 11/31] Another Enumerable updates --- Enumerable_Methods.rb | 34 +++++----------------------------- 1 file changed, 5 insertions(+), 29 deletions(-) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index 9a9f617..e52ccac 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -19,15 +19,13 @@ def my_each #my_each method def my_each_with_index #my_each_with_index method - myeachwithindex = 0 - while myeachwithindex < size - yield (self[myeachwithindex], myeachwithindex) - - myeachwithindex += 1 + k = 0 + while k < size + yield(self[k], k) + k += 1 end self end -end def my_select #my_select method @@ -94,30 +92,8 @@ def my_map(&proc) #my_map method mymap end end -end - - def my_map_again(myproc) #my_map_again method which takes a proc - self.my_each do |b| - mymapagain.push myproc.call(b) - end - mymapagain - end - - - def my_map_final myproc = nil #my_map_final method which can either take a proc or a block - mymapfinal = [] - self.my_each do |b| - if myproc == nil - mymapfinal.push yield(b) - else - mymapfinal.push myproc.call(b) - end - end - mymapfinal - end - - + def my_inject(param = self[0]) #my_inject method help = self help[1..help.length].each do |b| From ab140abc8166cafc668f06ba08749dcdea615c98 Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Wed, 6 Nov 2019 22:13:39 -0800 Subject: [PATCH 12/31] Work update --- Enumerable_Methods.rb | 119 +++++++++++++++++++++--------------------- 1 file changed, 60 insertions(+), 59 deletions(-) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index e52ccac..1e786ee 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -6,112 +6,111 @@ module Enumerable def my_each #my_each method - myeach = 0 - while myeach < size - yield self[myeach] - - myeach += 1 + result = self + m = 0 + while m < result.length + yield(result[m]) + m += 1 end - - self + result end -end def my_each_with_index #my_each_with_index method - k = 0 - while k < size - yield(self[k], k) - k += 1 + result = self + m = 0 + while m < result.length + yield(result[m], m) + m += 1 end - self + result end def my_select #my_select method - myselect = [] - while myselect < size - if yield (b) - myselect.push (b) - end - myselect + result = 0 + arr = [] + result.my_each do |k| + arr.push(k) if yield(k) end -end + arr +end def my_all? #my_all? method - myall = 0 - myall.my_each do |d| - return false unless yield(d) + result = self + result.my_each do |n| + return false unless yield(n) end true end - def my_any #my_any method - self.my_each { |n| return true if yield (n) } + def my_any? #my_any method + result = self + result.my_each do |n| + return true if yield(n) + end + false end + def my_none? #my_none method - mynone = true - self.my_each do |b| - return false if yield(b) + result = self + result.my_each do |d| + return false if yield(d) end true end def my_count #my_count method + result = self mycount = 0 - myhelp = self - myhelp.my_each do |a| - if block_given? - mycount += 1 if yield(a) - mycount += 1 + result.my_each do |f| + if block_given? && yield(f) + mycount += 1 + else + mycount = result.length end end mycount end - def my_map(&proc) #my_map method - return self.to_enum unless block_given? - - - mymap = [] - if self.class == Hash - self.each do |a, b| - - mymap << proc.call(a, b) - end - mymap - else - self.my_each do |c| - mymap << proc.call(c) + def my_map(proc = nil) #my_map method + result = [] + if proc + my_each do |q| + result << proc.call(q) + end + else + my_each do |q| + result << yield(q) + end end - mymap + result end -end def my_inject(param = self[0]) #my_inject method - help = self - help[1..help.length].each do |b| - param = yield(param, b) + myinject = param + result = self + result.my_each do |y| + next if param == yield + + param = yield(param, y) end param -end - - +end +end - def multiply_els #multiply_els method - my_inject {|mult, b | mult + b} - end +def multiply_els(par) #multiply_els method + par.my_inject(1) { |a, b| a * b } end - #Here are examples that could be used to test for some of the methods above. #Testing for my_each method @@ -141,5 +140,7 @@ def multiply_els #multiply_els method #array.my_inject #end +# puts arr.my_map { |i| i * 2} # => [2, 4, 6, 8, 10] +# puts multiply_els([2,4,5]) From d5b84f6196c04f008b514c0c5b882efc39db286d Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Sat, 9 Nov 2019 21:22:10 -0800 Subject: [PATCH 13/31] Enumerable methods tested and updated --- Enumerable_Methods.rb | 297 +++++++++++++++++++++++++++--------------- 1 file changed, 193 insertions(+), 104 deletions(-) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index 1e786ee..c733d67 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -1,12 +1,11 @@ # /usr/bin/ruby # frozen_string_literal: true - - module Enumerable - - def my_each #my_each method + #my_each method + def my_each result = self + return result.to_enum unless block_given? m = 0 while m < result.length yield(result[m]) @@ -15,9 +14,10 @@ def my_each #my_each method result end - -def my_each_with_index #my_each_with_index method +#my_each_with_index method +def my_each_with_index result = self + return result.to_enum unless block_given? m = 0 while m < result.length yield(result[m], m) @@ -26,9 +26,10 @@ def my_each_with_index #my_each_with_index method result end - -def my_select #my_select method - result = 0 +#my_select method +def my_select + result = self + return result.to_enum unless block_given? arr = [] result.my_each do |k| arr.push(k) if yield(k) @@ -36,111 +37,199 @@ def my_select #my_select method arr end - - def my_all? #my_all? method - result = self - result.my_each do |n| - return false unless yield(n) +# #my_all? method +def my_all?(param = nil) + k = true + if block_given? + my_each { |a| k = false unless yield a } end - true -end - - - def my_any? #my_any method - result = self - result.my_each do |n| - return true if yield(n) - end - false + if param.class == Regexp + my_each { |a| k = false unless a =~ param } + elsif param.class == Class + my_each { |a| k = false unless a.is_a?(param) } + elsif !param.nil? + my_each { |a| k = false unless a == param } end - - - def my_none? #my_none method - result = self - result.my_each do |d| - return false if yield(d) - end - true + if param.nil? + my_each { |a| k = false unless a } + end + k + end + +# #my_any? method +def my_any?(param = nil, &block ) + n = false + if block # &block is a reference to the block that is passed to the method + my_each { |b| n = true if block.call(b) } + elsif param.nil? + my_each { |b| n = true if b } + else + my_each { |b| n = true if param === b } end + n + end +# #my_none method +def my_none?(param = nil, &block) + !my_any?(param, &block) + end - def my_count #my_count method - result = self +#my_count method + def my_count(*param) mycount = 0 - result.my_each do |f| - if block_given? && yield(f) - mycount += 1 + length.times do |c| + if param.empty? + if block_given? + mycount += 1 if yield self[c] else - mycount = result.length + mycount = 1 + c end + elsif self[c] == param[0] + mycount += 1 + end end mycount + end + +# #my_map method +def my_map + return to_enum unless block_given? + + mymap = Array.new(length) + length.times { |q| mymap[q] = yield self[q] } + mymap + end + +#my_inject method + def my_inject(param = nil, param1 = nil) + result = is_a?(Range) ? min : self[0] + if block_given? + my_each_with_index { |myinject, q| result = yield(result, myinject) if q.positive? } + result = yield(result, param) if param + elsif param.is_a?(Symbol) || param.is_a?(String) + my_each_with_index { |myinject, q| result = result.send(param, myinject) if q.positive? } + elsif param1.is_a?(Symbol) || param1.is_a?(String) + my_each_with_index { |myinject, q| result = result.send(param1, myinject) if q.positive? } + result = result.send(param1, param) end - - - def my_map(proc = nil) #my_map method - result = [] - if proc - my_each do |q| - result << proc.call(q) - end - else - my_each do |q| - result << yield(q) - end - end - result - end - - - def my_inject(param = self[0]) #my_inject method - myinject = param - result = self - result.my_each do |y| - next if param == yield - - param = yield(param, y) - end - param -end -end - - -def multiply_els(par) #multiply_els method - par.my_inject(1) { |a, b| a * b } + result + end end - -#Here are examples that could be used to test for some of the methods above. - -#Testing for my_each method -#(To test each of these methods, you can take it out of the comment and go ahead with the testing ) - -#k = [1, 2, 3, 4, 5] -#k.my_each do |myeach| -#puts myeach -#end - -#Testing for my_each_with_index method - -#fruits = %w(Mango Pawpaw Cashew Pear Orange) -#fruits.my_each_with_index do |myeachwithindex, idx| -#puts "#{myeachwithindex} is the fruit with index #{idx}" -#end - -#Testing for my_select method - -#strings = %w(Angle Ball Cat Capstone Conquer) -#puts strings.my_select {|word| word.size > 3 } -#end - - -#To test for my_inject -#array = [1, 2, 3, 4, 5] -#array.my_inject -#end - -# puts arr.my_map { |i| i * 2} # => [2, 4, 6, 8, 10] - -# puts multiply_els([2,4,5]) - +#multiply_els method +def multiply_els(param) + param.my_inject(1) { |c, d| c * d } + end + +#Here are examples that could be used to test for the methods above. +# ########################################################3 + +# ary = [1, 2, 4, 2] +# puts ary.count #=> 4 +# puts ary.count(2) #=> 2 +# puts ary.count { |x| x%2 == 0 } #=> 3 +# puts "-----------" +# puts ary.my_count #=> 4 +# puts ary.my_count(2) #=> 2 +# puts ary.my_count { |x| x%2 == 0 } #=> 3 + +# puts %w[ant bear cat].none? { |word| word.length >= 3 } +# puts %w[ant bear cat].none? { |word| word.length >= 4 } +# puts %w[ant bear cat].none?(/t/) +# puts [1, 2i, 3.14].none?(Numeric) +# puts [nil, true, 99].none? +# puts [].none? +# puts [5, 5, 6].none?(6) +# puts [5, 5, 5].none?(6) +# puts "-----------------" +# puts %w[ant bear cat].my_none? { |word| word.length >= 3 } +# puts %w[ant bear cat].my_none? { |word| word.length >= 4 } +# puts %w[ant bear cat].my_none?(/t/) +# puts [1, 2i, 3.14].my_none?(Numeric) +# puts [nil, true, 99].my_none? +# puts [].my_none? +# puts [5, 5, 6].my_none?(6) +# puts [5, 5, 5].my_none?(6) + +# puts %w[ant bear cat].any? { |word| word.length >= 3 } +# puts %w[ant bear cat].any? { |word| word.length >= 4 } +# puts %w[ant bear cat].any?(/t/) +# puts [1, 2i, 3.14].any?(Numeric) +# puts [nil, true, 99].any? +# puts [].any? +# puts [5, 5, 6].any?(6) +# puts [5, 5, 5].any?(6) +# puts "-----------------" +# puts %w[ant bear cat].my_any? { |word| word.length >= 3 } +# puts %w[ant bear cat].my_any? { |word| word.length >= 4 } +# puts %w[ant bear cat].my_any?(/t/) +# puts [1, 2i, 3.14].my_any?(Numeric) +# puts [nil, true, 99].my_any? +# puts [].my_any? +# puts [5, 5, 6].my_any?(6) +# puts [5, 5, 5].my_any?(6) + +# puts %w[ant bear cat].all? { |word| word.length >= 3 } #=> true +# puts %w[ant bear cat].all? { |word| word.length >= 4 } #=> false +# puts %w[ant bear cat].all?(/t/) #=> false +# puts [1, 2i, 3.14].all?(Numeric) #=> true +# puts [nil, true, 99].all? #=> false +# puts [].all? #=> true +# puts [6, 6, 6].all?(6) +# puts [6, 6, 5].all?(6) +# puts "-----------------" +# puts %w[ant bear cat].my_all? { |word| word.length >= 3 } #=> true +# puts %w[ant bear cat].my_all? { |word| word.length >= 4 } #=> false +# puts %w[ant bear cat].my_all?(/t/) #=> false +# puts [1, 2i, 3.14].my_all?(Numeric) #=> true +# puts [nil, true, 99].my_all? #=> false +# puts [].my_all? #=> true +# puts [6, 6, 6].my_all?(6) +# puts [6, 6, 5].my_all?(6) + +# f = [1,2,3,4,5].select { |num| num.even? } +# g = [1,2,3,4,5].my_select { |num| num.even? } +# puts f.to_s +# puts g.to_s +# a = %w{ a b c d e f } +# f = a.select { |v| v =~ /[aeiou]/ } #=> ["a", "e"] +# g = a.my_select { |v| v =~ /[aeiou]/ } +# puts f.to_s +# puts g.to_s + +# hash = Hash.new +# %w(cat dog wombat).each_with_index { |item, index| +# hash[item] = index +# } +# puts hash.to_s +# puts "---each with index---" +# hash = Hash.new +# %w(cat dog wombat).my_each_with_index { |item, index| +# hash[item] = index +# } +# puts hash.to_s +# puts "---my each with index ---" +# puts %w(cat dog wombat).each_with_index +# puts "---each with index---" +# puts %w(cat dog wombat).my_each_with_index +# puts "---my each with index---" + +# a = [ "a", "b", "c" ] +# puts a.each { |x| print x, " -- " } +# puts "-------- each ---------" +# puts a.my_each { |x| print x, " -- " } +# puts '-------my each---------' +# puts a.each +# puts '-------- each ---------' +# puts a.my_each +# puts '-------my each---------' + +# self.to_enum + +# array = [1,5,8,7,9,5,5,55,5] +# p array.my_map + +# array = [1,5,8,7,9,5,5,55,5] +# p array.my_inject + +# puts multiply_els([10,20,30]) \ No newline at end of file From 055313222f878aaa9e04cf7af44bfa5b704240b4 Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Sat, 9 Nov 2019 21:36:01 -0800 Subject: [PATCH 14/31] some changes added --- Enumerable_Methods.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index c733d67..6036cf9 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -2,6 +2,7 @@ # frozen_string_literal: true module Enumerable + #my_each method def my_each result = self From d74e854b68ba60959311a23db33886f858ff1c82 Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Sun, 10 Nov 2019 22:40:14 -0800 Subject: [PATCH 15/31] Linter changes --- Enumerable_Methods.rb | 50 ++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index 6036cf9..b5f0896 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -2,23 +2,24 @@ # frozen_string_literal: true module Enumerable - - #my_each method + # my_each method def my_each - result = self - return result.to_enum unless block_given? - m = 0 - while m < result.length - yield(result[m]) - m += 1 - end - result - end + result = self + return result.to_enum unless block_given? + + m = 0 + while m < result.length + yield(result[m]) + m += 1 + end + result + end -#my_each_with_index method +# my_each_with_index method def my_each_with_index result = self return result.to_enum unless block_given? + m = 0 while m < result.length yield(result[m], m) @@ -27,9 +28,10 @@ def my_each_with_index result end -#my_select method +# my_select method def my_select result = self + return result.to_enum unless block_given? arr = [] result.my_each do |k| @@ -38,7 +40,7 @@ def my_select arr end -# #my_all? method + # my_all? method def my_all?(param = nil) k = true if block_given? @@ -53,12 +55,12 @@ def my_all?(param = nil) end if param.nil? my_each { |a| k = false unless a } - end + end k - end +end -# #my_any? method -def my_any?(param = nil, &block ) +# my_any? method +def my_any?(param = nil, &block) n = false if block # &block is a reference to the block that is passed to the method my_each { |b| n = true if block.call(b) } @@ -70,12 +72,12 @@ def my_any?(param = nil, &block ) n end -# #my_none method +# my_none method def my_none?(param = nil, &block) !my_any?(param, &block) end -#my_count method +# my_count method def my_count(*param) mycount = 0 length.times do |c| @@ -92,7 +94,7 @@ def my_count(*param) mycount end -# #my_map method +# my_map method def my_map return to_enum unless block_given? @@ -101,7 +103,7 @@ def my_map mymap end -#my_inject method +# my_inject method def my_inject(param = nil, param1 = nil) result = is_a?(Range) ? min : self[0] if block_given? @@ -117,13 +119,13 @@ def my_inject(param = nil, param1 = nil) end end -#multiply_els method +# multiply_els method def multiply_els(param) param.my_inject(1) { |c, d| c * d } end #Here are examples that could be used to test for the methods above. -# ########################################################3 +# ######################################################## # ary = [1, 2, 4, 2] # puts ary.count #=> 4 From 04715e78af40847e38062ade7900f254cf83d70d Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Wed, 13 Nov 2019 22:34:58 -0800 Subject: [PATCH 16/31] some changes added --- .rspec | 1 + Enumerable_Methods.rb | 37 +++++++++------- spec/spec_helper.rb | 100 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 123 insertions(+), 15 deletions(-) create mode 100644 .rspec create mode 100644 spec/spec_helper.rb diff --git a/.rspec b/.rspec new file mode 100644 index 0000000..c99d2e7 --- /dev/null +++ b/.rspec @@ -0,0 +1 @@ +--require spec_helper diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index b5f0896..0a245bc 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -1,18 +1,21 @@ # /usr/bin/ruby # frozen_string_literal: true +# rubocop:disable Metrics/PerceivedComplexity +# rubocop:disable Metrics/CyclomaticComplexity + module Enumerable # my_each method - def my_each - result = self - return result.to_enum unless block_given? - - m = 0 - while m < result.length - yield(result[m]) - m += 1 - end - result + def my_each + result = self + return result.to_enum unless block_given? + + m = 0 + while m < result.length + yield(result[m]) + m += 1 + end + result end # my_each_with_index method @@ -31,8 +34,8 @@ def my_each_with_index # my_select method def my_select result = self + return result.to_enum unless block_given? - return result.to_enum unless block_given? arr = [] result.my_each do |k| arr.push(k) if yield(k) @@ -42,7 +45,7 @@ def my_select # my_all? method def my_all?(param = nil) - k = true + k = true if block_given? my_each { |a| k = false unless yield a } end @@ -60,9 +63,9 @@ def my_all?(param = nil) end # my_any? method -def my_any?(param = nil, &block) +def my_any?( param = nil, &block ) n = false - if block # &block is a reference to the block that is passed to the method + if block my_each { |b| n = true if block.call(b) } elsif param.nil? my_each { |b| n = true if b } @@ -124,6 +127,9 @@ def multiply_els(param) param.my_inject(1) { |c, d| c * d } end +# rubocop:enable Metrics/PerceivedComplexity +# rubocop:enable Metrics/CyclomaticComplexity + #Here are examples that could be used to test for the methods above. # ######################################################## @@ -235,4 +241,5 @@ def multiply_els(param) # array = [1,5,8,7,9,5,5,55,5] # p array.my_inject -# puts multiply_els([10,20,30]) \ No newline at end of file +# puts multiply_els([10,20,30]) + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..251aa51 --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,100 @@ +# This file was generated by the `rspec --init` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # This allows you to limit a spec run to individual examples or groups + # you care about by tagging them with `:focus` metadata. When nothing + # is tagged with `:focus`, all examples get run. RSpec also provides + # aliases for `it`, `describe`, and `context` that include `:focus` + # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + config.filter_run_when_matching :focus + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + config.disable_monkey_patching! + + # This setting enables warnings. It's recommended, but in some cases may + # be too noisy due to issues in dependencies. + config.warnings = true + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = "doc" + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +=end +end From 852d9e59d42201a3de6cb86b4ca4ed2b41a8fd1d Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Wed, 13 Nov 2019 23:32:14 -0800 Subject: [PATCH 17/31] More changes added --- Enumerable_Methods.rb | 88 +++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index 0a245bc..97d5daf 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -20,65 +20,65 @@ def my_each # my_each_with_index method def my_each_with_index - result = self - return result.to_enum unless block_given? + result = self + return result.to_enum unless block_given? - m = 0 - while m < result.length - yield(result[m], m) - m += 1 - end - result + m = 0 + while m < result.length + yield(result[m], m) + m += 1 + end + result end # my_select method def my_select - result = self - return result.to_enum unless block_given? + result = self + return result.to_enum unless block_given? - arr = [] - result.my_each do |k| - arr.push(k) if yield(k) + arr = [] + result.my_each do |k| + arr.push(k) if yield(k) end arr end - # my_all? method +# my_all? method def my_all?(param = nil) - k = true - if block_given? - my_each { |a| k = false unless yield a } + k = true + if block_given? + my_each { |a| k = false unless yield a } end - if param.class == Regexp - my_each { |a| k = false unless a =~ param } + if param.class == Regexp + my_each { |a| k = false unless a =~ param } elsif param.class == Class my_each { |a| k = false unless a.is_a?(param) } elsif !param.nil? - my_each { |a| k = false unless a == param } + my_each { |a| k = false unless a == param } end if param.nil? - my_each { |a| k = false unless a } - end - k + my_each { |a| k = false unless a } + end + k end # my_any? method -def my_any?( param = nil, &block ) - n = false - if block - my_each { |b| n = true if block.call(b) } - elsif param.nil? - my_each { |b| n = true if b } - else - my_each { |b| n = true if param === b } - end - n - end +def my_any?(param = nil, &block) + n = false + if block + my_each { |b| n = true if block.call(b) } + elsif param.nil? + my_each { |b| n = true if b } + else + my_each { |b| n = true if param == b } + end + n +end # my_none method def my_none?(param = nil, &block) - !my_any?(param, &block) - end + !my_any?(param, &block) +end # my_count method def my_count(*param) @@ -95,7 +95,7 @@ def my_count(*param) end end mycount - end + end # my_map method def my_map @@ -104,14 +104,14 @@ def my_map mymap = Array.new(length) length.times { |q| mymap[q] = yield self[q] } mymap - end +end # my_inject method - def my_inject(param = nil, param1 = nil) - result = is_a?(Range) ? min : self[0] - if block_given? - my_each_with_index { |myinject, q| result = yield(result, myinject) if q.positive? } - result = yield(result, param) if param +def my_inject(param = nil, param1 = nil) + result = is_a?(Range) ? min : self[0] + if block_given? + my_each_with_index { |myinject, q| result = yield(result, myinject) if q.positive? } + result = yield(result, param) if param elsif param.is_a?(Symbol) || param.is_a?(String) my_each_with_index { |myinject, q| result = result.send(param, myinject) if q.positive? } elsif param1.is_a?(Symbol) || param1.is_a?(String) @@ -125,7 +125,7 @@ def my_inject(param = nil, param1 = nil) # multiply_els method def multiply_els(param) param.my_inject(1) { |c, d| c * d } - end +end # rubocop:enable Metrics/PerceivedComplexity # rubocop:enable Metrics/CyclomaticComplexity From 9cf0f17f039e0637efbc14722dc5e2ec945fe11e Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Thu, 14 Nov 2019 21:52:30 -0800 Subject: [PATCH 18/31] Some changes committetd --- Enumerable_Methods.rb | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index 97d5daf..8aca3b3 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -9,7 +9,7 @@ module Enumerable def my_each result = self return result.to_enum unless block_given? - + m = 0 while m < result.length yield(result[m]) @@ -97,8 +97,8 @@ def my_count(*param) mycount end -# my_map method -def my_map + # my_map method + def my_map return to_enum unless block_given? mymap = Array.new(length) @@ -106,20 +106,16 @@ def my_map mymap end -# my_inject method -def my_inject(param = nil, param1 = nil) - result = is_a?(Range) ? min : self[0] - if block_given? - my_each_with_index { |myinject, q| result = yield(result, myinject) if q.positive? } - result = yield(result, param) if param - elsif param.is_a?(Symbol) || param.is_a?(String) - my_each_with_index { |myinject, q| result = result.send(param, myinject) if q.positive? } - elsif param1.is_a?(Symbol) || param1.is_a?(String) - my_each_with_index { |myinject, q| result = result.send(param1, myinject) if q.positive? } - result = result.send(param1, param) - end - result +# my_inject method +def my_inject(start = 0) + i = 0 + accumulator = start + while i < self.size + accumulator = yield(accumulator, self[i]) + i += 1 end + accumulator +end end # multiply_els method From b1c42b7eef941093be82d29a0b6e7a6711641b04 Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Thu, 14 Nov 2019 23:19:20 -0800 Subject: [PATCH 19/31] Another changes added --- Enumerable_Methods.rb | 166 +++++++++++++++++++++--------------------- 1 file changed, 83 insertions(+), 83 deletions(-) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index 8aca3b3..7c8415d 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -4,12 +4,12 @@ # rubocop:disable Metrics/PerceivedComplexity # rubocop:disable Metrics/CyclomaticComplexity -module Enumerable + module Enumerable # my_each method - def my_each + def my_each result = self return result.to_enum unless block_given? - + m = 0 while m < result.length yield(result[m]) @@ -17,86 +17,86 @@ def my_each end result end + + # my_each_with_index method + def my_each_with_index + result = self + return result.to_enum unless block_given? -# my_each_with_index method -def my_each_with_index - result = self - return result.to_enum unless block_given? - - m = 0 - while m < result.length - yield(result[m], m) + m = 0 + while m < result.length + yield(result[m], m) m += 1 + end + result end - result -end -# my_select method -def my_select - result = self - return result.to_enum unless block_given? + # my_select method + def my_select + result = self + return result.to_enum unless block_given? - arr = [] - result.my_each do |k| - arr.push(k) if yield(k) + arr = [] + result.my_each do |k| + arr.push(k) if yield(k) end arr -end + end -# my_all? method -def my_all?(param = nil) - k = true - if block_given? - my_each { |a| k = false unless yield a } + # my_all? method + def my_all?(param = nil) + k = true + if block_given? + my_each { |a| k = false unless yield a } end - if param.class == Regexp - my_each { |a| k = false unless a =~ param } + if param.class == Regexp + my_each { |a| k = false unless a =~ param } elsif param.class == Class my_each { |a| k = false unless a.is_a?(param) } elsif !param.nil? - my_each { |a| k = false unless a == param } + my_each { |a| k = false unless a == param } end if param.nil? - my_each { |a| k = false unless a } + my_each { |a| k = false unless a } end - k -end - -# my_any? method -def my_any?(param = nil, &block) - n = false - if block - my_each { |b| n = true if block.call(b) } - elsif param.nil? - my_each { |b| n = true if b } - else - my_each { |b| n = true if param == b } - end - n -end - -# my_none method -def my_none?(param = nil, &block) - !my_any?(param, &block) -end - -# my_count method - def my_count(*param) - mycount = 0 - length.times do |c| - if param.empty? - if block_given? - mycount += 1 if yield self[c] - else - mycount = 1 + c - end - elsif self[c] == param[0] - mycount += 1 - end - end - mycount + k + end + + # my_any? method + def my_any?(param = nil, &block) + n = false + if block + my_each { |b| n = true if block.call(b) } + elsif param.nil? + my_each { |b| n = true if b } + else + my_each { |b| n = true if param == b } end + n + end + + # my_none method + def my_none?(param = nil, &block) + !my_any?(param, &block) + end + # my_count method + def my_count(*param) + mycount = 0 + length.times do |c| + if param.empty? + if block_given? + mycount += 1 if yield self[c] + else + mycount = 1 + c + end + elsif self[c] == param[0] + mycount += 1 + end + end + mycount + end + # my_map method def my_map return to_enum unless block_given? @@ -104,25 +104,25 @@ def my_map mymap = Array.new(length) length.times { |q| mymap[q] = yield self[q] } mymap -end - -# my_inject method -def my_inject(start = 0) - i = 0 - accumulator = start - while i < self.size - accumulator = yield(accumulator, self[i]) - i += 1 end - accumulator -end -end - -# multiply_els method -def multiply_els(param) - param.my_inject(1) { |c, d| c * d } -end + + # my_inject method + def my_inject(start = 0) + i = 0 + accumulator = start + while i < self.size + accumulator = yield(accumulator, self[i]) + i += 1 + end + accumulator + end + end + # multiply_els method + def multiply_els(param) + param.my_inject(1) { |c, d| c * d } + end + # rubocop:enable Metrics/PerceivedComplexity # rubocop:enable Metrics/CyclomaticComplexity From b86ad2f2f9dcb5dac1be295f4d65f623f22a919b Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Thu, 14 Nov 2019 23:35:40 -0800 Subject: [PATCH 20/31] New changes made --- Enumerable_Methods.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index 7c8415d..6ebc785 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -110,7 +110,7 @@ def my_map def my_inject(start = 0) i = 0 accumulator = start - while i < self.size + while i < size accumulator = yield(accumulator, self[i]) i += 1 end @@ -125,8 +125,8 @@ def multiply_els(param) # rubocop:enable Metrics/PerceivedComplexity # rubocop:enable Metrics/CyclomaticComplexity - -#Here are examples that could be used to test for the methods above. + +# Here are examples that could be used to test for the methods above. # ######################################################## # ary = [1, 2, 4, 2] @@ -232,10 +232,10 @@ def multiply_els(param) # self.to_enum # array = [1,5,8,7,9,5,5,55,5] -# p array.my_map +# p array.my_map # array = [1,5,8,7,9,5,5,55,5] -# p array.my_inject +# p array.my_inject # puts multiply_els([10,20,30]) From 6d8247bc4b0fc4889a501e539ed5778f5b9dc864 Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Thu, 28 May 2020 16:57:35 -0700 Subject: [PATCH 21/31] Modified stickler, rubocop, readme and new_spec file --- .rubocop.yml | 13 +++++++------ .stickler.yml | 3 ++- README.md | 10 ++++++---- spec/new_spec.rb | 0 4 files changed, 15 insertions(+), 11 deletions(-) create mode 100644 spec/new_spec.rb diff --git a/.rubocop.yml b/.rubocop.yml index c0c7636..7714447 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,11 +1,12 @@ AllCops: Exclude: - - "db/**/*" - - "config/**/*" + - "bin/*" + - "db/*" + - "config/*" - "Guardfile" - "Rakefile" DisplayCopNames: true - +​ Metrics/LineLength: Max: 120 Metrics/MethodLength: @@ -18,16 +19,16 @@ Metrics/ClassLength: Max: 150 Metrics/BlockLength: ExcludedMethods: ['describe'] - +​ Style/Documentation: Enabled: false Style/ClassAndModuleChildren: Enabled: false - +​ Layout/AlignHash: EnforcedColonStyle: key Layout/ExtraSpacing: AllowForAlignment: false Layout/MultilineMethodCallIndentation: Enabled: true - EnforcedStyle: indented + EnforcedStyle: indented \ No newline at end of file diff --git a/.stickler.yml b/.stickler.yml index 2a4eb06..c90ce2e 100644 --- a/.stickler.yml +++ b/.stickler.yml @@ -7,4 +7,5 @@ files: - "db/*" - "config/*" - "Guardfile" - - "Rakefile" + - "Rakefile" + \ No newline at end of file diff --git a/README.md b/README.md index bf3b241..e20ce1f 100644 --- a/README.md +++ b/README.md @@ -80,13 +80,15 @@ I learnt from this project that modules like Enumerable are the ultimate in DRY # Acknowledgements: -https://medium.com/yello-offline/ruby-the-enumerable-module-under-the-hood-some-caveats-f640ce39a07d +[Medium - The Enumerable Module](https://medium.com/yello-offline/ruby-the-enumerable-module-under-the-hood-some-caveats-f640ce39a07d) -https://github.com/othneildrew/Best-README-Template +[Best ReadMe Template](https://github.com/othneildrew/Best-README-Template) -https://www.theodinproject.com/courses/ruby-programming/lessons/advanced-building-blocks +[The Odin Project - Advanced Building Blocks](https://www.theodinproject.com/courses/ruby-programming/lessons/advanced-building-blocks) -https://www.vikingcodeschool.com/falling-in-love-with-ruby/the-enumerable-module +[Vikings - The Enumerable Module ](https://www.vikingcodeschool.com/falling-in-love-with-ruby/the-enumerable-module) + +To as many that supported and guided me towards this project, my regards to them all. diff --git a/spec/new_spec.rb b/spec/new_spec.rb new file mode 100644 index 0000000..e69de29 From 49ca4a358aef9e610808eea98adf8cab81c8ff71 Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Thu, 28 May 2020 17:02:38 -0700 Subject: [PATCH 22/31] Readme file modified --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e20ce1f..ca527df 100644 --- a/README.md +++ b/README.md @@ -68,11 +68,11 @@ Distributed under the MIT Licence. See Licence for more informaton # Contributor(s): -Kingsley McSimon Ogbonna @KingsleyMcSimon +[Kingsley McSimon Ogbonna](https://github.com/KingsleyMcSimon) # Link To The Project On Github: -https://github.com/KingsleyMcSimon/Enumerable-Methods +[Enumerable-Methods](https://github.com/KingsleyMcSimon/Enumerable-Methods) # What Was Learnt During The Project: From cee1de4ed7b915121c45d38628e1ba1c127baea5 Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Wed, 1 Jul 2020 22:49:57 -0700 Subject: [PATCH 23/31] .rubocop.yml updated --- .rubocop.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 7714447..df0c385 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -7,7 +7,7 @@ AllCops: - "Rakefile" DisplayCopNames: true ​ -Metrics/LineLength: +Layout/LineLength: Max: 120 Metrics/MethodLength: Include: ["app/controllers/*"] @@ -31,4 +31,4 @@ Layout/ExtraSpacing: AllowForAlignment: false Layout/MultilineMethodCallIndentation: Enabled: true - EnforcedStyle: indented \ No newline at end of file + EnforcedStyle: indented From 505c401a6d75f4192bc41ae3b039b260852dfebf Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Wed, 1 Jul 2020 22:56:41 -0700 Subject: [PATCH 24/31] Readme file updated --- README.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/README.md b/README.md index ca527df..08a61a9 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ To get started, here below are the steps that needs to be taken in order to achi 11. Modify your #my_map method to take a proc instead. 12. Modify your #my_map method to take either a proc or a block. It won’t be necessary to apply both a proc and a block in the same #my_map call since you could get the same effect by chaining together one #my_map call with the block and one with the proc. This approach is also clearer, since the user doesn’t have to remember whether the proc or block will be run first. So if both a proc and a block are given, only execute the proc. -# contributing: +# Contributing: In this project, your contributions towards helping in improving this project is woild be well accomodated. With that, the project will get better rating and give programmers at any level the ability learn, be inspired and create better content. @@ -89,6 +89,3 @@ I learnt from this project that modules like Enumerable are the ultimate in DRY [Vikings - The Enumerable Module ](https://www.vikingcodeschool.com/falling-in-love-with-ruby/the-enumerable-module) To as many that supported and guided me towards this project, my regards to them all. - - - From c53830e8b745ecee187f338bd948b8bd9d9d9881 Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Wed, 1 Jul 2020 23:35:52 -0700 Subject: [PATCH 25/31] rubocop updated --- .rubocop.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index df0c385..4715692 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,12 +1,11 @@ AllCops: Exclude: - - "bin/*" - - "db/*" - - "config/*" + - "db/**/*" + - "config/**/*" - "Guardfile" - "Rakefile" DisplayCopNames: true -​ + Layout/LineLength: Max: 120 Metrics/MethodLength: @@ -19,12 +18,12 @@ Metrics/ClassLength: Max: 150 Metrics/BlockLength: ExcludedMethods: ['describe'] -​ + Style/Documentation: Enabled: false Style/ClassAndModuleChildren: Enabled: false -​ + Layout/AlignHash: EnforcedColonStyle: key Layout/ExtraSpacing: @@ -32,3 +31,4 @@ Layout/ExtraSpacing: Layout/MultilineMethodCallIndentation: Enabled: true EnforcedStyle: indented + \ No newline at end of file From 4696659ec03945eb2c3293db9613ab7f299d2b42 Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Fri, 3 Jul 2020 17:18:12 -0700 Subject: [PATCH 26/31] enumerable_methods file updated --- Enumerable_Methods.rb | 118 +----------------------------------------- 1 file changed, 1 insertion(+), 117 deletions(-) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index 6ebc785..327061f 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -122,120 +122,4 @@ def my_inject(start = 0) def multiply_els(param) param.my_inject(1) { |c, d| c * d } end - -# rubocop:enable Metrics/PerceivedComplexity -# rubocop:enable Metrics/CyclomaticComplexity - -# Here are examples that could be used to test for the methods above. -# ######################################################## - -# ary = [1, 2, 4, 2] -# puts ary.count #=> 4 -# puts ary.count(2) #=> 2 -# puts ary.count { |x| x%2 == 0 } #=> 3 -# puts "-----------" -# puts ary.my_count #=> 4 -# puts ary.my_count(2) #=> 2 -# puts ary.my_count { |x| x%2 == 0 } #=> 3 - -# puts %w[ant bear cat].none? { |word| word.length >= 3 } -# puts %w[ant bear cat].none? { |word| word.length >= 4 } -# puts %w[ant bear cat].none?(/t/) -# puts [1, 2i, 3.14].none?(Numeric) -# puts [nil, true, 99].none? -# puts [].none? -# puts [5, 5, 6].none?(6) -# puts [5, 5, 5].none?(6) -# puts "-----------------" -# puts %w[ant bear cat].my_none? { |word| word.length >= 3 } -# puts %w[ant bear cat].my_none? { |word| word.length >= 4 } -# puts %w[ant bear cat].my_none?(/t/) -# puts [1, 2i, 3.14].my_none?(Numeric) -# puts [nil, true, 99].my_none? -# puts [].my_none? -# puts [5, 5, 6].my_none?(6) -# puts [5, 5, 5].my_none?(6) - -# puts %w[ant bear cat].any? { |word| word.length >= 3 } -# puts %w[ant bear cat].any? { |word| word.length >= 4 } -# puts %w[ant bear cat].any?(/t/) -# puts [1, 2i, 3.14].any?(Numeric) -# puts [nil, true, 99].any? -# puts [].any? -# puts [5, 5, 6].any?(6) -# puts [5, 5, 5].any?(6) -# puts "-----------------" -# puts %w[ant bear cat].my_any? { |word| word.length >= 3 } -# puts %w[ant bear cat].my_any? { |word| word.length >= 4 } -# puts %w[ant bear cat].my_any?(/t/) -# puts [1, 2i, 3.14].my_any?(Numeric) -# puts [nil, true, 99].my_any? -# puts [].my_any? -# puts [5, 5, 6].my_any?(6) -# puts [5, 5, 5].my_any?(6) - -# puts %w[ant bear cat].all? { |word| word.length >= 3 } #=> true -# puts %w[ant bear cat].all? { |word| word.length >= 4 } #=> false -# puts %w[ant bear cat].all?(/t/) #=> false -# puts [1, 2i, 3.14].all?(Numeric) #=> true -# puts [nil, true, 99].all? #=> false -# puts [].all? #=> true -# puts [6, 6, 6].all?(6) -# puts [6, 6, 5].all?(6) -# puts "-----------------" -# puts %w[ant bear cat].my_all? { |word| word.length >= 3 } #=> true -# puts %w[ant bear cat].my_all? { |word| word.length >= 4 } #=> false -# puts %w[ant bear cat].my_all?(/t/) #=> false -# puts [1, 2i, 3.14].my_all?(Numeric) #=> true -# puts [nil, true, 99].my_all? #=> false -# puts [].my_all? #=> true -# puts [6, 6, 6].my_all?(6) -# puts [6, 6, 5].my_all?(6) - -# f = [1,2,3,4,5].select { |num| num.even? } -# g = [1,2,3,4,5].my_select { |num| num.even? } -# puts f.to_s -# puts g.to_s -# a = %w{ a b c d e f } -# f = a.select { |v| v =~ /[aeiou]/ } #=> ["a", "e"] -# g = a.my_select { |v| v =~ /[aeiou]/ } -# puts f.to_s -# puts g.to_s - -# hash = Hash.new -# %w(cat dog wombat).each_with_index { |item, index| -# hash[item] = index -# } -# puts hash.to_s -# puts "---each with index---" -# hash = Hash.new -# %w(cat dog wombat).my_each_with_index { |item, index| -# hash[item] = index -# } -# puts hash.to_s -# puts "---my each with index ---" -# puts %w(cat dog wombat).each_with_index -# puts "---each with index---" -# puts %w(cat dog wombat).my_each_with_index -# puts "---my each with index---" - -# a = [ "a", "b", "c" ] -# puts a.each { |x| print x, " -- " } -# puts "-------- each ---------" -# puts a.my_each { |x| print x, " -- " } -# puts '-------my each---------' -# puts a.each -# puts '-------- each ---------' -# puts a.my_each -# puts '-------my each---------' - -# self.to_enum - -# array = [1,5,8,7,9,5,5,55,5] -# p array.my_map - -# array = [1,5,8,7,9,5,5,55,5] -# p array.my_inject - -# puts multiply_els([10,20,30]) - + \ No newline at end of file From 373b0a1af8bc9eb70ead13c443211e653816ff21 Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Sun, 19 Jul 2020 23:01:36 -0700 Subject: [PATCH 27/31] Enum methods modified --- Enumerable_Methods.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index 327061f..d95b1b4 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -17,7 +17,7 @@ def my_each end result end - + # my_each_with_index method def my_each_with_index result = self From e3ddced699969c3615c0861eb6a8a80842d9c0da Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Thu, 23 Jul 2020 01:48:01 -0700 Subject: [PATCH 28/31] enumerable_methods file updated --- Enumerable_Methods.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index d95b1b4..1906723 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -111,15 +111,13 @@ def my_inject(start = 0) i = 0 accumulator = start while i < size - accumulator = yield(accumulator, self[i]) i += 1 end accumulator end - end # multiply_els method def multiply_els(param) param.my_inject(1) { |c, d| c * d } end - \ No newline at end of file +end From e4c8e31eb5d1a58e6049728c91fb9895951de1b4 Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Wed, 5 Aug 2020 01:47:34 -0700 Subject: [PATCH 29/31] enumerable methods updated --- Enumerable_Methods.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index 1906723..b9edf37 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -121,3 +121,5 @@ def multiply_els(param) param.my_inject(1) { |c, d| c * d } end end + +# (5..10).my_inject { |sum, n| sum + n } From 8719c20e02387ad5edfc45b2cecabea150ed67db Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Thu, 3 Sep 2020 04:07:23 -0700 Subject: [PATCH 30/31] # my_inject method --- Enumerable_Methods.rb | 51 +++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index b9edf37..c3dd023 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -5,7 +5,8 @@ # rubocop:disable Metrics/CyclomaticComplexity module Enumerable - # my_each method + # my_each method + UNDEFINED = Object.new def my_each result = self return result.to_enum unless block_given? @@ -63,10 +64,10 @@ def my_all?(param = nil) end # my_any? method - def my_any?(param = nil, &block) + def my_any?(param = nil) n = false - if block - my_each { |b| n = true if block.call(b) } + if block_given? + my_each { |b| n = true if yield(b) } elsif param.nil? my_each { |b| n = true if b } else @@ -76,9 +77,15 @@ def my_any?(param = nil, &block) end # my_none method - def my_none?(param = nil, &block) - !my_any?(param, &block) + def my_none?(param = nil) + n = true + if block_given? + my_each { |b| n = false if yield(b) } + else + n = !my_any?(param) end + n +end # my_count method def my_count(*param) @@ -105,15 +112,31 @@ def my_map length.times { |q| mymap[q] = yield self[q] } mymap end - - # my_inject method - def my_inject(start = 0) - i = 0 - accumulator = start - while i < size - i += 1 + + def my_inject(prev = UNDEFINED, choice = UNDEFINED) + vol = prev + vol = 0 if prev == UNDEFINED + case choice + + when UNDEFINED + if block_given? + my_each do |b| + vol = yield(vol, b) + end + vol + elsif prev.is_a?(Symbol) + my_inject do |mem, object| + mem.method(prev).call(object) + end + end + else + if choice.is_a?(Symbol) + vol = prev + my_inject(sum) do |mem, object| + mem.method(choice).call(object) + end + end end - accumulator end # multiply_els method From e9894562a94dc484b6ac7bc8087aa91810bee0a8 Mon Sep 17 00:00:00 2001 From: kingsley McSimon Ogbonna Date: Thu, 3 Sep 2020 04:09:47 -0700 Subject: [PATCH 31/31] my_any?, my_none? and my_inject methods worked on as recommended --- Enumerable_Methods.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/Enumerable_Methods.rb b/Enumerable_Methods.rb index c3dd023..5379ef0 100644 --- a/Enumerable_Methods.rb +++ b/Enumerable_Methods.rb @@ -144,5 +144,3 @@ def multiply_els(param) param.my_inject(1) { |c, d| c * d } end end - -# (5..10).my_inject { |sum, n| sum + n }