# Re: RubyJS - Convert Ruby to Javascript

**URL:** <https://www.ruby-forum.com/t/re-rubyjs-convert-ruby-to-javascript/81934>\
**Category:** Ruby\
**Created:** [January 16, 2007, 12:39pm UTC](https://www.ruby-forum.com/t/re-rubyjs-convert-ruby-to-javascript/81934 "2007-01-16T12:39:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![michaeln](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b19c9b/32.png) [@michaeln](https://www.ruby-forum.com/u/michaeln)\
**Post date:** [January 16, 2007, 12:39pm UTC](https://www.ruby-forum.com/t/re-rubyjs-convert-ruby-to-javascript/81934/1 "2007-01-16T12:39:01Z")

</div>

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/](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

---

<div class="post-metadata">

**Author:** ![michaeln](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/b19c9b/32.png) [@michaeln](https://www.ruby-forum.com/u/michaeln)\
**Post date:** [January 16, 2007, 1:21pm UTC](https://www.ruby-forum.com/t/re-rubyjs-convert-ruby-to-javascript/81934/2 "2007-01-16T13:21:07Z")

</div>

Michael N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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/](http://www.yvon-thoraval.com/ruby2js/ntecs.de/hg-projects/rubyjs/essai/)  
index.html\>

Again, vielen dank 😉
