These are chat archives for opal/opal

6th
Mar 2019
Leon
@illogikal
Mar 06 15:40
This may be a newbie code question but how do you convert a js object to a opal hash? I have a section of code I'm writing in opal for business logic and I want to call it from js
Jan Biedermann
@janbiedermann
Mar 06 16:04
Hash.new(json_object)
Leon
@illogikal
Mar 06 16:27
{a: 1} this javascript object?
doesn't seem to work
I'm experimenting with importing opal into a node project
I compile it with the opal cmd line compiler and then am exporting the methods i want available from the exported code like
return (def hi(args)
  args = Hash.new args
  # puts args['hi'], args['there']
end)
I can then access this from plain JS like ExportedOpal().$hi({hi: 'there'})
I want to figure out how to convert js objects into hashes, i tried the Hash.new but doesn't seem to work
Jan Biedermann
@janbiedermann
Mar 06 16:40
Opal.Hash.$new({a: 1})['$[]']('a‘) works for me, prints 1
oh, maybe you have to:
Hash.new(`args`)
to make sure you get tha bare js version of args
Guillaume Grossetie
@Mogztter
Mar 06 17:40
Hey @janbiedermann I'm trying to package the Opal runtime as an ES6 modules (strict mode)
Jan Biedermann
@janbiedermann
Mar 06 18:02
supercool :)
Leon
@illogikal
Mar 06 19:35
And how do you convert hash back to object? .to_n doesn't work
Elia Schito
@elia
Mar 06 19:36
Leon you might need to require “native”
G. Gibson
@mistergibson
Mar 06 19:37
@illogikal : I was thinking $jQuery.ParseJSONFunction(#{AHash.to_json})
in tick quotes
Jared White
@jaredcwhite
Mar 06 23:51
Hi everybody! Long (very long) time no talk! I'm checking in because my domain "opalist.co" is expiring at the end of the month, and I'd be happy to transfer it over to someone in the Opal community if that's of interest. Otherwise I'll let it lapse. The site/newsletter's been stagnant or offline for quite some time…