Skip to content

Instantly share code, notes, and snippets.

@rogsmith
Last active November 6, 2015 04:02
Show Gist options
  • Save rogsmith/5f723ffd99e70f9c63df to your computer and use it in GitHub Desktop.
Save rogsmith/5f723ffd99e70f9c63df to your computer and use it in GitHub Desktop.
therubyracer + commonsjsrb
context = V8::Context.new timeout: timeout
js = CommonJS::Environment.new(context, path: "#{Rails.root}/lib/javascripts")
context["_"] = js.require('underscore.js')
context['data'] = "[1,2,3,4]"
source = "(function(){return _.map(JSON.parse(data), function(num){ return num * 5 });});"
res = context.eval(source)
# res is a #<V8::Function:0x007feaf195a720
# if I then try
res.call()
#it gives me a #<V8::Array:0x007feaf1689f50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment