You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$stdout = Object.new.tap { |obj|
def obj.write(i)
JS.global[:document].write(i)
end
}
Then we can simply use puts, which is convenient.
But how to write to console.log?
Past this point if we use:
JS.global[:document].write "foobar"
It will no longer write to console.log, instead just to primary stdout in the browser.
Is there a way to still write to console.log somehow? Could this be added to FAQ?
If not, could there be a way to show this? I'd like to get debug-like output right
via console.log() as well, so being able to write onto console.log even when having
modified $stdout, would be convenient, in my opinion. Could such a way be added
in addition to ruby.wasm?
console is a JS global just like document so you can access it the same:
JS.global[:console].log('hello')
Feel free to make whatever shortcut you find comfortable:
# global variable
$console =JS.global[:console]
$console.log('hello')# Kernel patch# (this is where `puts` is defined too)moduleKerneldefconsoleJS.global[:console]endendconsole.log('hello')console.error('bad')
Activity
rubyFeedback commentedon Mar 3, 2024
Hmm it seems "pp" can be used to do so. Still I think it may be useful to add it to a FAQ entry.
On a semi-related note, when I use "pp", the console also says:
And so forth. Not sure why. I am using:
https://cdn.jsdelivr.net/npm/@ruby/3.3-wasm-wasi@2.5.0/dist/browser.script.iife.js
sfcgeorge commentedon May 6, 2024
consoleis a JS global just likedocumentso you can access it the same:Feel free to make whatever shortcut you find comfortable: