He may have been told when to be there.
ANYTHING is possible, but there was really no way to do so since the timing of Oswalds transfer was in flux.
Warren Commission investigator David Belin said that postal inspector Harry Holmes arrived unannounced at the Dallas police station and, upon invitation by the investigators, questioned Oswald, thus delaying his transfer by half an hour.[42] Belin concluded that, had Ruby been part of a conspiracy, he would have been downtown 30 minutes earlier.[42]
https://en.m.wikipedia.org/wiki/Jack_Ruby
Jack Ruby was at the nearby Western Union office sending a money order and then went directly to the police station. He arrived just as Oswald was led into the crowd by dumb luck.
The thing is "just so happened" he was nearby at a Western Union carrying a gun goes over to the police station at just at the right time. Walks up to Oswald and shoots him!
Afterwards when interviewed Ruby clams up and never talked about it. He took any secrets to his grave.