Created
January 17, 2011 19:36
-
-
Save cowboyd/783330 to your computer and use it in GitHub Desktop.
Proof of concept for making all ruby available to javascript.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'v8' | |
require 'openssl' | |
class Module | |
def [](name) | |
self.const_get(name) | |
end | |
end | |
class RubyTopLevel | |
def [](constant) | |
Object.const_get(constant) | |
end | |
end | |
V8::Context.new do |cxt| | |
cxt['Ruby'] = RubyTopLevel.new | |
cxt.eval('var cipher = new Ruby.OpenSSL.Cipher("aes-128-cbc")') | |
cxt.eval('cipher.decrypt') | |
puts cxt['cipher'] #=> #<OpenSSL::Cipher:0x1015c7f40> | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
General solution to this problem: