A way of dispatching Ruby classes and objects as COM OLE objects, via win32ole.
Useful for IE intergration:
require 'win32ole'
require_relative 'RubyIDispatch.rb'
#Instantiate IE
ie = WIN32OLE.new('InternetExplorer.Application')
ie.navigate("about:blank")
sleep(0.1) until !ie.busy
#Write HTML including setVar() function to install BHO.
html = <<Heredoc
<html>
<head>
<script>
window.Ruby = {}
document.setVar = function(name,val){
window.Ruby[name]=val;
}
</script>
</head>
<body>
<h1>Hello!</h1>
</body>
</html>
Heredoc
ie.document.write(html)
ie.visible = true
#Create OLE class for File object:
OLEFile = WIN32OLE::getDispatch(File)
#Create BHO:
ie.document.setVar("File",OLEFile)
After calling the above script, RubyFile can now be accessed directly from JavaScript!
f = Ruby.File.new("my/cool/file")
console.log(f.read())
f.puts("some data")
f.close
// Also access to singleton methods
Ruby.File.write("my/other/file","Some cool Ruby function")
- Add class wrapper. E.G.
WIN32OLE::getDispatch(File)
- Add pure method wrapper. E.G.
WIN32OLE::getDispatch(method(:someMethod))
- Add object wrapper. E.G.
WIN32OLE::getDispatch(someObject)
- Wrap returned objects from other ruby functions.
- Wrap blocks so they are callable from JavaScript as callback functions.