But before we get into what Opal Ruby is, let’s start by saying what Opal Ruby is not, as these are the three most obvious use cases, and Opal Ruby is a poor fit for all three.
There are quite a few frontend frameworks that come with their languages – like Imba, Elm, and arguably Svelte. Opal Ruby does not come with any framework attached.
This is quite awkward, as for your frontend needs you’ll need some kind of a framework, and unless that framework is Opal-aware, it will be difficult to use them together.
It’s possible to build a framework on top of Opal Ruby, like notably Hypestack, which uses uses Opal and React. There are also some wrappers like opal-jquery, and I even created opal-d3 once upon a time, but I don’t actively maintain it anymore.
Another thing we might want to do is run big Ruby codebases in the browser, like we can run Ruby on the JVM with JRuby.
This is not going to work. Opal Ruby has so many differences from regular Ruby, that your chance of any significant codebase working out of the box is slim.
This is not completely hopeless, as you could tweak your codebase a bit here and there to be able to run in both regular Ruby and Opal Ruby. I guess a good comparison would be writing a library that runs in both Python 2 and Python 3, I hope that doesn’t give you any flashbacks.
There’s also another way to run Ruby in a browser that can handle this use case better. Ruby can be compiled to WebAssembly, which as of now is a terrible platform that’s only good for cryptomining malware, and lacks a lot of functionality we’d need to run real programs there, but there’s some hope it might become good enough over the next few years. That’s also what PyScript is doing.
Many environments come with bad languages, and there’s been quite a few languages designed as a pretty much drop-in replacements, like:
- Kotlin for JVM
- YueScript for Lua
- and so on
So Opal Ruby is not going to work like that. Any drop-in replacement attempt needs two things:
- near seamless interoperability with the original language
- low performance overhead
Now that we established what Opal Ruby is not, over the next few episodes we’ll explore what it is.