As ennuikiller said, you must define what you wish to name the variable(s) that is passed back from the yield
statement. This has to do with a variable's scope. The scope inside of the block that you pass to test_method
does not know about the i
variable. You can actually call this whatever you wish.
For instance, you could do the following:
def test_method
["a", "b", "c"].map { |i| yield(i) }
end
p test_method { |some_variable_name| some_variable_name.upcase }
Just because the test method knows about it, it does not means that the block that you pass to the test method will know about it.
Edit 1: To give a little more information, you can redefine test_method
as follows if it makes it a little bit more clear:
def test_method(&block)
if not block.nil?
["a", "b", "c"].map { |i| yield(i) }
end
end