I know what blocks are and how to utilize the ones that already exist. However, it seems like I do not know how to create them as I’m totally confused by the first problem as well as the instructions and spec errors. I’m hoping that if i get a few pointers on the 1st problem, I can move on through deduction.
The instructions included in the spec file:
# # Topics
#
# * blocks
# * closures
# * yield
# * loops
This is the most vague set of instructions I have received. i’ve been looking back at the AA section on blocks as well as the codeacademy block section which I’ve already completed but it doesn’t get me any closer to understanding what I’m supposed to do here. There have been no block/proc related exercises except the ones in Rspec. I’m totally floored that the rspec exercises are much more difficult than the regular exercises, I left them till the end because the forking was not working earlier on.
After examining multiple syntax examples of blocks, I wrote a few to see if any would pass the test:
def reverser
yield(“hello”)
end
result = reverser {|string| string.reverse}
This one does not pass the test despite returning the correct answer on repl and pry. The spec error is:
Failure/Error: expect(result).to eq(“olleh”)
expected: "olleh"
got: "hello"
The next one is modeled exactly after the Codeacademy lesson on yielding to blocks:
def reverser(string)
yield string
end
reverser(“hello”) {|string| string.reverse}
This one also passes on repl and pry, here is the spec error:
Failure/Error: result = reverser do
ArgumentError:
wrong number of arguments (given 0, expected 1)
Furthermore, both specs includes an essential line that I do not understand at all: some silly block functions reverser reverses the string returned by the default block. What is the default block mentioned in this case? Why do these output correctly on repl and pry but do not pass the test in rspec?