You can just signal object B when the raycast detects that it's collided with it. Something like:
signal raycast_A_object_hit(object)
func _physics_process(delta):
if $raycast.is_colliding():
emit_signal("raycast_A_object_hit", $raycast.get_collider())
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:
func on_raycast_A_object_hit(object):
if object == self:
#do stuff
You'll have to connect the signal of course, either in the script or in the editor.