Num. 4


#1

so i did what the instructions said to do but i keep getting this Oops, try again. Did you call yield_name a second time with your name in the block?

and this is my code

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}." }

Now call the method with your name!

def yield_name(name)
puts "In the method! Let's yield."
yield("Tesla")
puts "In between the yields!"
yield(name)
puts "Block complete! Back in the method."
end
yield_name("Tesla"){|n| puts "My name is #{n}."}
i dont understand what im doing wrong can someone please explane to me


#2

Are you trying to define the same method twice?


#3

Call yield_name with your name as a parameter. Make sure to pass in a block that puts "My name is #{your name here}!"
?
Hint

Your code should look identical to the code on line 7, only your name should be between yield_name's parentheses.

@arjofocolovi this is the instructions and from what i understand and my teacher to its to write the same code but put my name in and not the other one. Do you this we are reading the instructions wrong??


#4

okay i figured it out i was not so-post to only use the last line on the code instead of the hole this.. silly me but i still don't understand what the code is doing


#5

ANSWER:
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}." }
yield_name("SHASHANK UPADHYAY") { |n| puts "My name is #{n}."}


#6

It's just copying the block that contains "Eric", and changing Eric to your own name... (If your name is Eric... you're in luck!).


#7

The instructions felt like they were working up to asking you to write a nice chunk of code but really all they wanted you to do was have the method yield to your name the same way they did with Eric. You really could have just replaced Eric with anything.

In my case I added the same line with a name in it and it printed twice, commented out Eric's line and it ended up being what they wanted. They're just trying to show you how you can manipulate the yield command to do some interesting things like store names.