Coder Social home page Coder Social logo

my-each's Introduction

My Each

Objectives

  1. Define a method that uses yield and a while loop to pass each element of a collection to a block.
  2. Gain a deeper understanding of the common iterator #each.

Instructions

Note: Some of the tests may be passing before you write any code. But, in order to get all of the tests passing you'll need to use the yield keyword correctly.

Now that you know how the yield method works, try to write your own version of the #each method without using the #each method provided by Ruby.

You'll be building out the content of the #my_each method. This method should accept an argument of an array and use the while loop to iterate over each member of that array, yielding each element contained in the array to a block.

Here's an example of what should happen when you call your my_each method:

collection = [1, 2, 3, 4]
my_each(collection) do |i|
  puts i
end

This should output:

1
2
3
4

and return:

#=> [1, 2, 3, 4]

Just like the real #each method.

my-each's People

Contributors

ahimmelstoss avatar annjohn avatar arelenglish avatar aviflombaum avatar dakotalmartinez avatar deniznida avatar fislabstest avatar fs-lms-test-bot avatar ga-be avatar ihollander avatar irmiller22 avatar kthffmn avatar loganhasson avatar markedwardmurray avatar maxwellbenton avatar msuzoagu avatar octosteve avatar pletcher avatar sarogers avatar sgharms avatar sophiedebenedetto avatar victhevenot avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

my-each's Issues

Just yield.

In the previous section (the section right before) yield and blocks, yield is taught by being put after the method is called with do or {}. But according to the technical coach who helped me, (Marcel Galang) didn't like me putting do or {} after the method was called. All I had to do was put yield anywhere in the method. And nothing after it was called. Then he told me I was overthinking it pass the tests and move on. Which made no sense because I was taught a certain way how yield works. I guess maybe this should be placed after return from yield statements.

The instructions to this lab are misleading

The instructions ask to create an "each" like method using "while" and "yield". For the example, it shows a method that "puts" each element and then expects to receive the array itself in return. Whereas, that is not possible without calling out the method itself again. And the tests are passing without actually using "puts" anywhere.
screen shot 2016-09-12 at 9 23 00 pm
screen shot 2016-09-12 at 9 23 38 pm
screen shot 2016-09-12 at 9 24 05 pm

OPEN IDE button in Chrome Stopped working

OPEN IDE button just stopped working in my Chrome browser (around lesson 44ish). It also doesn't work in firefox. IE asks me to download Chrome. (Chrome 79.0.3945.79 on Windows 10)
I believe Chrome is according to updated .
I tried restarting my computer and the browser and logging back in.

EACH LAB issue

I can't pass the lab because it raised an error saying not to use while loop but the instruction is saying to use while loop for this lab.

It's easy to fool 7/8 of the spec tests by a simple 'puts' instead of yield.

I was answering a student's question, and it came up that 7/8 of the spec tests were being passed without even needing to use the keyword with code along these lines:

def my_each(array)
counter = 0
while counter < array.length do
puts "hello"
counter += 1
end
return array
end

It might be worth making the spec tests more specific to the yield keyword for the various labs in this section.

compliment

Just wanted to say that making students code their own interpretations of these basic methods was a fantastic way to illustrate the concepts. Thanks!

Testing error

I am confused, the lab instructions and the lesson before teach me to use a while loop inside of the method to create my own #each. The problem is the rspec test says not to use a while loop, in test two. Is this an error in the test? I've google how to make my each loops and they all use while loops.

difficulty understanding yield

I solved the lab eventually, but I still don't feel like I really understand how to use each. In part, I think i'm still confused about blocks/enclosures in Ruby. Granted, that's a pretty complex topic that iOS doesn't touch until week 6 or so. Just felt like I really struggled accomplishing this lab. I'm sorry I can't give very specific advice about how to improve the lesson at this point.

@SophieDeBenedetto

Warning messages when I run 'learn' - please see comment below for entire learn output

/home/beingy/code/labs/my-each-v-000/spec/my_each_spec.rb:61: warning: assigned but unused variable - tas_original
/home/beingy/code/labs/my-each-v-000/spec/my_each_spec.rb:105: warning: assigned but unused variable - expected
/home/beingy/code/labs/my-each-v-000/spec/my_each_spec.rb:106: warning: assigned but unused variable - times_called
/usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54: warning: loading in progress, circular require considered harmful - /usr/local/rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry.rb
from /usr/local/rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in <main>' from /usr/local/rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:ineval'
from /usr/local/rvm/gems/ruby-2.2.3/bin/rspec:23:in <main>' from /usr/local/rvm/gems/ruby-2.2.3/bin/rspec:23:inload'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/exe/rspec:4:in <top (required)>' from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:45:ininvoke'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:78:in run' from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:92:inrun'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:106:in setup' from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:inload_spec_files'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:in each' from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:inblock in load_spec_files'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:in load' from /home/beingy/code/labs/my-each-v-000/spec/my_each_spec.rb:2:in<top (required)>'
from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:in require' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:inrescue in require'
from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in require' from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry.rb:150:in<top (required)>'
from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire'
from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/cli.rb:107:in <top (required)>' from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/cli.rb:39:inadd_plugin_options'
from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/cli.rb:39:in each' from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/cli.rb:40:inblock in add_plugin_options'
from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/plugins.rb:38:in load_cli_options' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire'
from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require' from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-nav-0.2.4/lib/pry-nav/cli.rb:1:in<top (required)>'
from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:in require' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:inrescue in require'
from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in require' from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-nav-0.2.4/lib/pry-nav.rb:2:in<top (required)>'
from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire'
from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-nav-0.2.4/lib/pry-nav/pry_ext.rb:1:in <top (required)>' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire'
from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require' /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54: warning: loading in progress, circular require considered harmful - /usr/local/rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry.rb from /usr/local/rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in

'
from /usr/local/rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in eval' from /usr/local/rvm/gems/ruby-2.2.3/bin/rspec:23:in'
from /usr/local/rvm/gems/ruby-2.2.3/bin/rspec:23:in load' from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/exe/rspec:4:in<top (required)>'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:45:in invoke' from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:78:inrun'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:92:in run' from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:106:insetup'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:in load_spec_files' from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:ineach'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:in block in load_spec_files' from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:inload'
from /home/beingy/code/labs/my-each-v-000/spec/my_each_spec.rb:2:in <top (required)>' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:inrequire'
from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in rescue in require' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:inrequire'
from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry.rb:150:in <top (required)>' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire'
from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require' from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/cli.rb:107:in<top (required)>'
from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/cli.rb:39:in add_plugin_options' from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/cli.rb:39:ineach'
from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/cli.rb:40:in block in add_plugin_options' from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/plugins.rb:38:inload_cli_options'
from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire'
from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-nav-0.2.4/lib/pry-nav/cli.rb:1:in <top (required)>' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:inrequire'
from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in rescue in require' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:inrequire'
from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-nav-0.2.4/lib/pry-nav.rb:2:in <top (required)>' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire'
from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require' from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-nav-0.2.4/lib/pry-nav/pry_ext.rb:2:in<top (required)>'
from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire'
from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-nav-0.2.4/lib/pry-nav/tracer.rb:1:in <top (required)>' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire'
from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require' /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54: warning: loading in progress, circular require considered harmful - /usr/local/rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry.rb from /usr/local/rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in'
from /usr/local/rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in eval' from /usr/local/rvm/gems/ruby-2.2.3/bin/rspec:23:in'
from /usr/local/rvm/gems/ruby-2.2.3/bin/rspec:23:in load' from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/exe/rspec:4:in<top (required)>'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:45:in invoke' from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:78:inrun'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:92:in run' from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/runner.rb:106:insetup'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:in load_spec_files' from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1359:ineach'
from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:in block in load_spec_files' from /usr/local/rvm/gems/ruby-2.2.3/gems/rspec-core-3.4.4/lib/rspec/core/configuration.rb:1361:inload'
from /home/beingy/code/labs/my-each-v-000/spec/my_each_spec.rb:2:in <top (required)>' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:inrequire'
from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in rescue in require' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:inrequire'
from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry.rb:150:in <top (required)>' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire'
from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require' from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/cli.rb:107:in<top (required)>'
from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/cli.rb:39:in add_plugin_options' from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/cli.rb:39:ineach'
from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/cli.rb:40:in block in add_plugin_options' from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-0.10.3/lib/pry/plugins.rb:38:inload_cli_options'
from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire'
from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-nav-0.2.4/lib/pry-nav/cli.rb:1:in <top (required)>' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:39:inrequire'
from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:in rescue in require' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:128:inrequire'
from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-nav-0.2.4/lib/pry-nav.rb:3:in <top (required)>' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire'
from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require' from /usr/local/rvm/gems/ruby-2.2.3/gems/pry-nav-0.2.4/lib/pry-nav/commands.rb:1:in<top (required)>'
from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in require' from /usr/local/rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:inrequire'

my_each
does not call on each
does not call on puts
calls on while
iterates over each element
yields the correct element
can handle an empty collection
returned array contains the same elements as the original collection
does not modify the original collection
block is run n times
only single element is passed into block

Finished in 0.01507 seconds (files took 0.72076 seconds to load)
10 examples, 0 failures

Test conflicts with instructions

Hi there! The instructions for this lab state that #my_each should use a while loop

instructions

but there is a test that it "does not call on while or puts"

test

which leads to the following rspec error when using "while" within the method

rspec_output

Broken test

The instructions in this lab say to use a while loop, but then the tests checks to make sure you are NOT using a while loop.

Error with Rspec File Test

After running learn against my code for this lab I received the following errors indicating a problem in the Rspec tests : /home/amjack59/code/labs/my-each-v-000/spec/my_each_spec.rb:61: warning: assigne
d but unused variable - tas_original                                            
/home/amjack59/code/labs/my-each-v-000/spec/my_each_spec.rb:105: warning: assign
ed but unused variable - expected                                               
/home/amjack59/code/labs/my-each-v-000/spec/my_each_spec.rb:106: warning: assign
ed but unused variable - times_called  

Would you please look into this and let me know how to proceed. Thanks.

Hi,

Hi,

The lab description tells you to use a while loop, but the test says not to use "while" - is this an error?

My_Each - confusing instructions

I'd just like to send some feedback on this lab - I found the instructions incredibly confusing. The lab says "Here's an example of what should happen when you call your my_each method:
collection = [1, 2, 3, 4]
my_each(collection) do |i|
puts i
end"
That led me to believe that the correct way to complete the lab was to use puts. The tests themselves were also confusing, and it took a long to understand that all that was required was to execute the block, not produce an output.

I would suggest to change the example, or clarify that the end result will NOT be printing anything out.

RSpec passing false positives

As per README:

Here's an example of what should happen when you call your my_each method:

collection = [1, 2, 3, 4]
my_each(collection) do |i|
 puts i
end

This should output:

1
2
3
4

and return:

#=> [1, 2, 3, 4]

Just like the real .each method.

Two passing PRs in this lab's repo (commits e7a640 & d9d9cd) contain variants of the following code:

def my_each(array) 
  while array.length > 0
    yield(array)
    array.pop
  end
  return array
end

which outputs:

1
2
3
4
1
2
3
1
2
1
=> []

The above code should not satisfy the parameters set forth in the README, and therefore seems to be an instance of RSpec passing a false positive.

In addition, the README instructs students to:

...try to write your own version of the .each method without using the .each method provided by Ruby.

yet a passing PR (commit 4155fb) utilizes .each within my_each. This seems like another instance of RSpec passing a false positive, and including another test to prevent this in the future may be an appropriate solution.

my_each_spec.rb - line 15-19

If I'm understanding this right, in the below code, the expectation should be corrected to: expect(contents).to_not include("while" && "puts")

  it "does not call on while or puts" do 
    file = File.read('./my_each.rb')
    contents = file.split(" ")
    expect(contents).to_not include("while" || "puts")
  end

I apologize if I'm wrong. Thanks for the awesome lessons!

Issue with Tests

The tests pass both when the yield argument is the current element and when it is the element's index. I.e. both these methods pass all tests:

def my_each(array)
i = 0
while i < array.length
yield(array[i])
i += 1
end
array
end

def my_each(array)
i = 0
while i < array.length
yield i
i += 1
end
array
end

I'm not sure this RSpec test is actually testing for anything

I can't think of a situation in which the below invocation of #my_each(tas) do |ta| end could possibly modify the variable tas within this RSpec test:

it "does not modify the original collection" do
    tas = ['arel', 'jon', 'logan', 'spencer']
    # array may be modified by the iteration function so
    # we cannot use it for verifying the results
    # therefore we create a new copy using the clone method
    tas_original = tas.clone

    # run the method
    my_each(tas) do |ta|
      # Do nothing on yield
    end

    # is verifying if the array we passed to method
    # has not been modified
    expect(tas).to eq(tas_original)
end

Where does yield come from?

Completing this lab I feel like knowing what yield did or was in the first place would have made things easier and make this lab more robust as a learning tool. I didn't check all of the labs previous to this, yet I think that this is the first time in the curriculum that yield has ever been mentioned as yield and not a different way of using proc.

This lab could do a lot more in terms of providing guidance by simply linking to Stack Overflow which indeed shows us that yield is "syntactic sugar", or the equivalent to a proc. That way the lab that proceeds this titled Blocks Vs. Procs Vs. Lambdas makes a lot more sense because we know where yield fits into the equation.

a little more expl of yield and enums

explain how yield is really whats happening under the hood of enums and take that explanation out of enums readme cuz too advanced for intro.
Enumerator methods can be called on hashes and arrays and take blocks as their argument, where the block is yielded to for every item in the array or hash. In other words, when we call:

array = [1, 2, 3, 4]
array.each do |num|
num * 2
end
You can imagine it as: array.each(some code that gets executed on each member of the array)

The block is the code between the do, end syntax. You can also define a block with curly braces, {}.

Missing Content?

I feel like I'm going crazy— the lab reads "Now that you know how the yield method works, try to write..." but no previous lesson has covered the yield method. Is there missing content or is this a sink or swim situation?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.