Oops - apologies for the typos in that code.
Anyway, I've got it minimally working using this code, but I really need to understand Javascript's prototypal inheritance a bit better to make any more progress!
class Square
def area(length)
length * length
end
end
cxt = V8::Context.new
cxt["Square"] = Square
coffeescript = "class BlueSquare extends Square"
cxt.eval CoffeeScript.compile(coffeescript, :bare => true)
cxt.eval "BlueSquare.prototype = new Square"
cxt.eval "azure = new BlueSquare"
cxt.eval "azure.area(3)"
On Thursday, November 29, 2012 8:15:32 AM UTC, Toby Nicholas wrote:
Hi folks,
I'm wondering if it's possible to use CoffeeScript inheritance with Ruby classes passed to the V8 context... something like:
class Square
def area(length)
length * length
end
end
cxt["Square"] = Square
coffeescript = "class BlueSquare extends Square"
cxt.eval CoffeeScript.compile(cs), :bare => true
cxt.eval "azure = new BlueSquare"
cxt.eval "azure.area(3)"
# => V8::Error: Object #<BlueSquare> has no method 'area'
I've tried poking around but I can't figure out quite how Ruby classes are being represented. Worth persevering with, or am I barking up the wrong tree?
Thanks!
Toby