There's so much weird stuff about Ruby - Vickie Adams is sure he was outside the TSBD pretending to be a reporter on the day of the assassination, he shows up at the Oswald press conference, he's filmed in the halls of the DPD etc. He is so suspect but I have to agree, it isn't a mafia hit or some other conspiracy driven event, it seems to be, as you say, a spur of the moment madness.
That's because Ruby himself
was weird. He seemed to enjoy mixing with people he considered important, reporters, police, even the 'mob', inserting himself where he didn't belong, there's plenty of examples of him doing that. Would a psychiatrist label that as someone with a serious inferiority complex? He was also known to have a hair-trigger temper...that's why his nickname was 'sparky', he was also known for having abrupt mood swings, sometimes violent ones. I can quite imagine a man like Ruby having a momentary flash of madness, he even admitted as much himself, when he saw Oswald smirking. He was also surprised at the public reaction...he expected to be treated as a hero. Give an unstable man like that easy access to a gun and....