目前,我正在尝试Hash
从 JS 中获取 Ruby 格式的内容。
我有一个看起来像这样的 JS 模块
module.exports = {
key1: "val",
key2: {
key3: "val3"
}
...
}
这只是一个字符串给我。我知道 ExecJS 在这里可能会有所帮助,但我不确定将其转换为 Hash 的最佳方法是什么。
我目前正在尝试做这样的事情
contents.prepend("var module = {exports: {}};\n")
context = ExecJS.compile contents
context.eval('module.exports').to_hash
但是当给它一个像上面这样的字符串时,我从 JSON gem 中得到一个解析错误。