Why does `require 'native'` throw an exception in opalrb?

29 Views Asked by At

I'm taking baby steps with opalrb, here is my main.rb:

require 'native'

def main
    puts "hi from the main function in main.rb"
end

def demoButton
    outputDiv = Element.find('output').get(0)
    puts outputDiv.methods.sort
end

It's included within <head> after opal.js and ...opal-parser.js" onload="Opal.load('opal-parser')" but the console shows an exception thrown:

{
  message: "cannot load such file -- native",
​  name: "LoadError",
​  stack: ""
}

native seems to be part of the opal standard library, so why is there a problem including it?

1

There are 1 best solutions below

0
hmdne On

Add this:

<script src="https://cdn.opalrb.com/opal/current/native.js"></script>

The stdlib part (like native) of Opal isn't included in opal.js. For a full list of stdlib, take a look here:

https://cdn.opalrb.com/opal/current/index.html