These are chat archives for opal/opal
Yeah, it's not like in MRI where method lookup is very expensive — it uses a method cache internally, but that's unnecessary in a JS VM. My guess as to his motive is that metaprogramming is fun. ;-)
@catmando In your example,
div points to the same function in the VM as
method_missing, wired up at compile time. The only extra cost is inside
method_missing, which is probably reduced to almost 0 after a couple executions of it when the JIT gets ahold of it. Would be best not to conjecture and run benchmarks instead. :-)
@fkchang Hey, thanks for replying! This is my setup: https://github.com/JikkuJose/react-lab/tree/feature-opal_support
I am trying to import a simple Ruby class to a typical React project.
This is the Ruby file: https://github.com/JikkuJose/react-lab/blob/feature-opal_support/src/js/app/para.rb
This is how I am hoping to us it: https://github.com/JikkuJose/react-lab/blob/feature-opal_support/src/js/app.jsx#L9
Note: Now, I am referring to the jsx file instead of the .rb file. But didn't work when I was using it.
opalrb-loaderbe listed in
Opal.YourClass. To create its instance use
.$new(), to call your own method call
.$your_method(). For your code it should be
@iliabylich I was able to use the Ruby class like you mentioned. I understand its not very pretty, but I was just trying to see if it was possible. It definitely looks awful to write
Opal.Paragraph.$new().$text(); but the capability to do Ruby along side JS feels cool. Certainly not for production, but to see the value of webpack.
Loud Thought: If Ruby classes could have been addressed like normal es6 classes this would have been a great way to use Opal along side, so that we could code in either Ruby or es6.
app/application.rb)...is that possible ?
require 'opal' require 'browser' # This may not be necessary Opal.use_gem 'browser'
require 'opal' require 'browser'
require 'opal' Opal.use_gem 'browser'
Uncaught NoMethodError: undefined method `use_gem' for undefined
Opal.use_gem 'browser'. If you added it, you need to restart your server.
Browser::Canvasclass? I've started playing around with it but its API appears to be quite different from the native one