Skip to content

Commit c84591b

Browse files
ledsunkateinoigakukun
authored andcommitted
Instead of to_json, use to_js for each property
This is to handle objects other than plain old data.
1 parent e0b1f73 commit c84591b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

ext/js/lib/hash.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
require "json"
2-
31
class Hash
42
# Convert a hash to a JavaScript object
53
def to_js
6-
JS.eval("return #{self.to_json}")
4+
new_object = JS.eval("return {}")
5+
self.each do |key, value|
6+
new_object[key] = value
7+
end
8+
new_object
79
end
810
end

0 commit comments

Comments
 (0)