The biggest problem you may encounter with an engine swap is your vintage of Ranger, I believe the cluster, anti-theft and ECU all got integrated and it makes for swap headaches.
That said, any swap is possible with enough time and money. The big problem with any straight 6 (or worse, straight 8) is the length. Ford actually went through the trouble to re-design the timing chain cover and accessories to cram the 302/5.0 into the Explorer which at the time used the same engine bay size and layout as the Ranger. These modifications shaved a few inches off the length which improved the fit. Even at that, the 302 pretty well fills every bit of space. I’m currently working on my second swap of this nature. And if you’re looking to build power, it’s a good swap. Eventually I plan to build a 302 into a 331 stroker for it, just because.