Yielding With Parameters - help


#1

The yield method is still confusing to me. So can someone please give a better explanation of this code? The explanation given on the side confuses me even more.

def yield_name(name)
puts "In the method! Let's yield."
yield("Kim")
puts "In between the yields!"
yield(name)
puts "Block complete! Back in the method."
end

yield_name("Eric") { |n| puts "My name is #{n}." }


#2

you need to rewrite the method call again

yield_name("Eric") { |n| puts "My name is #{n}." }

yield_name("your_name") { |n| puts "My name is #{n}." }


#3

Sorry to bring this one up again but I think I've applied the solution suggested above and Im still being told there is an error. I understand the lesson but I need this to work to have completed the ruby course :slightly_smiling:

I have the code as:

def yield_name(name)
puts "In the method! Let's yield."
yield("Kim")
puts "In between the yields!"
yield(name)
puts "Block complete! Back in the method."
end

yield_name("Alier") { |n| puts "My name is #{n}." }

It is correctly outputting my name in the console but not letting me pass that step. Instead its asking me did i call yield_name a second time with my name in the block


#4

your code is fine but you remove the other yield_name that one
yield_name("Eric") {|n| puts "My name is #{n}"} copy it past it on top of your yield_name


#5

that is work.
very helpfull it


#6

That didn't work for me...


#7

read the instructions carefully :slight_smile: needs a ! instead of . for your name's case.


#8

I agree, it does not work


#9

Should have work, try check whether u mess with the original code.
reset the code and retype
yield_name("your_name") { |n| puts "My name is #{n}." }
into it.
Remember, dont delete the one with Eric in it
The exclamation mark doesnt matter. Comma works well for me