There's opal-irb
and opal-jquery
and vienna
but is there any way to use gems directly in the browser via Opal?
Opal can be worn as finger rings/pendants made of silver, platinum, gold/white gold or Panchdhatu.
The planet of Venus clashes with the following celestial bodies: The Sun, The Moon, and Jupiter. This is why the Opal Gemstone should not be worn with Ruby, Pearl, or Topaz gemstones.
What are rubies used for? The most common use for rubies is jewelry—stunning jewelry! However, both natural and synthetic rubies are used in a variety of applications—such as watchmaking, medical instruments, and lasers—because of their incredible strength and red fluorescence.
While opals are very pretty, they're soft and susceptible to scratches. Try wearing them as a necklace or bracelet rather than as a ring to expose them to fewer dings and scrapes.
You can add a gem's lib
path to Opal load paths by using Opal.use_gem
Common pitfalls are:
``
and %x{}
)Available tools to fix/workaround some of those issues are:
Opal::Processor.stub_file('fileutils')
RUBY_ENGINE
,
example:
unless RUBY_ENGINE == 'opal'
unparsable/breaking code here
end
You can look at the opal-rspec
source code to see this stuff in action:
https://github.com/opal/opal-rspec
As usual the answer is yes and no at the same time, depending on your point of view. Opal will turn your ruby (all of it) into JavaScript and provides an appropriate run time. If you require a gem it will be required during the compilation process and will be included into the generated JavaScript. You may freely use the generated ruby classes in your ruby code (which again ends up being compiled into JavaScript).
So you can require gems, but bear in mind that their requires will also be required, so will end up with a nightmare of a JavaScript file if you are not careful. Technically you are still not running ruby in the browser, it all had to be compiled to JavaScript for that purpose. However you can run the code generated from your ruby and the required gems, though it will have become JavaScript during the process (and you will have to debug it as such). There are some limitations to this approach though, you will have to bear in mind JavaScript Number
and String
properties (aka only immutable String
s), but within these limits you may share your code between the server and the client.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With