Ruby’s send
method will invoke private methods as well as public ones. In this case it ends up calling the Kernel#p
method, which is a private method on all objects. You can see this by passing another argument to p
that will be printed:
xml.send(:p, "A message that will be printed")
Another way to demonstrate this would be to use public_send
, which doesn’t look at private methods and so will trigger method_missing
and generate the tag.
xml.public_send(:p)
Of course you don’t really need to use public_send
, since p
doesn’t use any special characters and you can use it directly as a method:
xml.p