This is an instance of Puppet::Resource, which is being converted here to an instance of (a subclass of) Puppet::Type.  The define of to_ral as copy_as_resource.to_ral is in Puppet::Parser::Resource, not in Puppet::Resource.

But maybe you're saying: why bother making a copy when you could just call to_ral directly on the resource (since to_ral doesn't modify self).  That's a good point.