Create your own greeter and proc

Here are the instructions.

  1. Create a method, greeter, that takes no arguments and yields to a block.
  2. Create a Proc, phrase, that puts “Hello there!”. Pass this to greeter instead of a block. (Don’t forget to pass &phrase instead of just phrase!)

This is my code.

def greeter
yield
end

phrase = Proc.new do
“Hello there!”
end

greeter(&phrase)

This is what prints out in the console.

“Hello there!”

This is the error that I have.

“Oops, try again. It looks like you didn’t print anything to the console. Did you call your greeter method and pass it the phrase proc?”

I’m confused of where the error is. Please show me how to fix this.

1 Like

Must be very sleepy to catch this. The error is that I did not have puts in front of “Hello there!” to display it.

1 Like

Does anyone know why I keep getting an error for this:
def greeter(name) yield(name) end greeter("Jack") {|x| puts "Welcome to greeter #{x}"} phrase=Proc.new {|x| puts "Hello there!"} greeter.select(&phrase)
the error says
wrong number of arguments (0 for 1)
but I can still progress to the next lesson.

I’m just learning jackmiller, but the first part of the instruction asks us to

“Create a method, greeter, that takes no arguments”.

Your method has a parameter attached, suggesting that there will be an argument when the method is called.

1 Like

You have a parameter called (name)… There is not meant to be a parameter because there is not meant to be an argument. I feel the code should look like this instead.

def greeter
yield
end

Thank you for your post and your contribution to this page is appresiated.

It is very good that you can add simple informative ifnormation and I admire that you do not post randomm and long posts that explain things in a way that need explaining. I think that the way you are short and get to the point and incude a short example are ways of a great man or woman and you will go well in life if you continue this though it.

You have my higest praises.