Because the string is created first, which means calling def1, and then the whole string is passed into puts.
We can expand puts "some text #{def1}" out to understand.
string = "some text " + def1.to_s
puts string
As you can see, def1 is called to create the string. def1 prints out 1 itself, it does not return anything (it returns nil). Then the whole string is printed.
That's how all function calls work. The arguments are evaluated, the the function is called.
You'd need to call def1 after printing the prefix.
print "some text "
def1
This is a reason why it's often better to have a function return a value rather than print it itself.
def1within the interpolation is executed before to invoketo_son it, after that it returnsnil. Is the wayputsworks.