You can just signal object B when the raycast detects that it's collided with it. Something like:
What that'll do is, when the raycast collides with any object, it'll pull a reference to that object and then emit a signal saying that it's hit something. That signal will also contain that object reference, so then you could have code in object_B that goes like:
if object == self:
You'll have to connect the signal of course, either in the script or in the editor.