Re: RubyJS - Convert Ruby to Javascript

Une Bévue wrote:

example).

not at all, as i said, i’ve just simplified your HelloWorld class but
add the document.getEllementById... and change yours p(something) to
self.puts(something) here it is :

<http://www.yvon-thoraval.com/ruby2js/ntecs.de/hg-projects/rubyjs/essai/
essai.rb>

Change #{ … } to #< … >

def puts(str)
document.getElementById("STDOUT")['innerHTML'] = document.getElementById("STDOUT")['innerHTML'] + "#<str>\n"
end

And if you move “puts” into module Kernel, then you can also use the “p”
method, which is equivalent to puts(obj.inspect).

Regards,

Michael

Michael N. [email protected] wrote:

Change #{ … } to #< … >

def puts(str)
document.getElementById("STDOUT")['innerHTML'] = document.getElementById("STDOUT")['innerHTML'] + "#<str>\n"
end

And if you move “puts” into module Kernel, then you can also use the “p”
method, which is equivalent to puts(obj.inspect).

OK fine, thanks.

first i had a js error at line 609 (unterminated string) of the
resulting file because i get :

document… = document… + "_str
";

instead of having :

document… = document… + _str + “\n”;

and, after correcting that point i get from js console :

Error: uncaught exception: [object Object]

my html file being at :

<http://www.yvon-thoraval.com/ruby2js/ntecs.de/hg-projects/rubyjs/essai/
index.html>

Again, vielen dank :wink:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs