There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
If I understand correctly “def greeter(n)” >>n is a parameter, not an argument?
I’m not sure if I’m supposed to be writing anything with yield (the explanation of yield in this chapter was severely lacking and I would’ve appreciated a bit more theory or something to explain exactly what it’s doing and if I’m supposed to write arguments/parameters after it…?
Regardless, I’ve written this below and then checked the hint and it was exactly what I’d already written, and it prints out what it’s supposed to, but I get an error saying this: “Did you call greeter(&proc) so that it puts ‘Hello there!’ to the console?”
Which I answer “yes” to, because it does print that as it’s meant to, but I know I’m getting this error because of some stupid syntax error, that it wants me to hit return between lines somewhere or something, or I that I was supposed to put something in parenthesis around the method and I’m getting confused by the wording of the questions here (yet again its not as explicit as I need it to be, this is getting tiring)
Because of the explanation of what you have to do and the example on Hint, I don’t get why you should add --> greeter(&phrase) at the end. See the complete solution below:
Bit late to the party but for those that will follow, that is simply because you’re printing twice to the console (within the &phrase, and the puts here just before greeter).
Did I miss something in an earlier lesson about defining methods without parameters, or was that not covered? My assumption would be syntax defining a method without a parameter would be invalid, because a method couldn’t take an argument without a parameter. Aside from completing this exercise, why would you ever define a method without a parameter?
In Ruby it is common to define variables using a method. These methods do not need a parameter since their only purpose is to return the value of that variable.
This doesn’t answer OP’s question. In your case nothing is being passed in, the method just returns a value, in this exercise a code block is being passed in and yielded, all without referencing the parameters in the method. I’m also confused about this.
yield allows additional instructions to be passed to a method. There is no parameter. We see in this example how the block argument is immediately referred to by the yield keyword. Without the block an error would result. yield is calling the block.