Skip to content

Instantly share code, notes, and snippets.

@supermario
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save supermario/b58b630822cabf13e571 to your computer and use it in GitHub Desktop.
Save supermario/b58b630822cabf13e571 to your computer and use it in GitHub Desktop.
Opalrb 0.6.3 to_n issue.
# Running this to get compiled opalrb js
opal -c test.rb > build/test.rb.js
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<script src='lib/opal.min.js'></script>
</head>
<body>
<script src='build/test.rb.js'></script>
</body>
</html>
# Mimic the React class we'll eventually be tying into
`React = { createClass: function(t) { console.log(t.render()); } };`
require 'opal'
require 'native'
params = {
render: -> {
return "nice"
}
}
react_class = `React.createClass(#{params.to_n})`
# Last line throws:
# Uncaught NoMethodError: undefined method `to_n' for {"render"=>#<Proc:undefined>}opal.min.js:2
# (anonymous function)opal.min.js:2
# def.$raiseopal.min.js:1
# def.$method_missing.TMP_1opal.min.js:1
# method_missing_stubtest.rb.js:12
# (anonymous function)test.rb.js:13
# (anonymous function)
# Yet same code on is fine: opalrb.org/try
# http://opalrb.org/try/#code:%60React%20%3D%20%7B%20createClass%3A%20function(t)%20%7B%20t.render()%3B%20%7D%20%7D%3B%60%0A%0Arequire%20'opal'%0Arequire%20'native'%0A%0Aparams%20%3D%20%7B%0A%20%20render%3A%20-%3E%20%7B%0A%20%20%20%20puts%20%22nice%22%0A%20%20%7D%0A%7D%0A%0Areact_class%20%3D%20%60React.createClass(%23%7Bparams.to_n%7D)%60
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment