Feature: puts
& p
can handle native JS objects not wrapped by Native
for simple debugging/troubleshooting
#2630
Labels
Is your feature request related to a problem? Please describe.
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
With Opal 1.8.2, if I try to use
puts
orp
on a native JS object like{a: 1, b: 2}
, the Opal application crashes with either an error aboutrespond_to?
not existing to test existence ofto_s
, orinspect
not existing.Trying this Ruby code in an Opal frontend (Rails Asset Pipeline Sprockets Opal app):
Causes this error:
Trying this Ruby code in Opal:
Causes this error:
This can be very frustrating for Ruby developers used to
puts
andp
who are new to Opal and might have received a JS/JSON object from a Web API ajax call or some third party JS library. Those methods not working when a simpleconsole.log
works in JS drives Opal newbs crazy!Describe the solution you'd like
A clear and concise description of what you want to happen.
I think this can be handled automatically by
puts
&p
by having them defer toconsole.log(nativeObj)
automatically if the Ruby way of handling things fails (norespond_to?
method,to_s
method, orinspect
method).@hmdne said the following about this solution in the Opal Slack channel:
Describe alternatives you've considered
A clear and concise description of any alternative solutions or features you've considered.
For now, I can drop down to native JS with ticks and use
console.log
in this situation.Additional context
Add any other context or screenshots about the feature request here.
JRuby tries to shield Ruby developers from Java details as much as possible. It would be cool if at least, in
puts
&&p
, Opal developers are shielded from JavaScript low-level details relating to the Ruby implementations of these methods like not havingto_s
,respond_to?
orinspect
. Defaulting toconsole.log
in those situations should be a good enough solution to avoid driving Opal newbies crazy.The text was updated successfully, but these errors were encountered: