Try it Yourself: Why does yielding to put does not generate a new line?


#1

I expected the below code to generate the following output:

method talking
dog

Why does yielding back to the block did not apply the new line of the puts from the block and returned this instead:

method talkingdog

def double(x)
print "method talking"
yield x
end

double(4) {puts "dog"}


#2

Puts adds a newline character after, not before


#3

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