9. Creating your own! Please explain this! Thank you!


#1



This sounds ridiculous but I tend to play and check if my code will pass however this one returns error message in console yet I still don't know why this one passed. Can someone explain this why it's correct?

Thank you so much!!! :kissing_heart:


ERROR MESSAGE:

(ruby):3: syntax error, unexpected tCONSTANT, expecting $end
yield(phrase)Proc.new {|m| m puts "Hello, there!"}


Replace this line with your code. 

def greeter
    yield(phrase)
end
yield(phrase)Proc.new {|m| m puts "Hello, there!"}


x = greeter.map(&phrase)


#2

Should read,

phrase = Proc.new { ... }

We assign the Proc to a variable. The block should only contain puts "Hello, there!" and yield does not take a parameter.

Not sure what you are mapping, but that is not asked for in the instructions.

def greeter
  yield
end

phrase = Proc.new do
    puts "Hello there!"
end

greeter(&phrase)

The SCT is not a very rigorous test mechanism and may permit a pass even when there are console errors. Naturally, the console error takes precedence so we need to be able to interpret them and solve the issues if we really want to learn. Don't let the SCT be your guide. Let Ruby do the leading.


#3

What I'm trying to map here is - if yield would take any parameter? out of curiosity and now I understand that yield is mainly to invoke blocks only.

It frustrates me a bit that SCT isn't precise obviously! and yes, my priority is a console error free with a knowledge on how that codes worked.

I just really wanted to have a discussion as to why SCT accepted that kind of code with errors. :grin: Maybe other tend to skip and not even figured out what was wrong on there codes which is not a good practice. :disappointed_relieved:

Anyway, Thank you so much for a clear explanation! :kissing_heart:


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.