Module: JSON
- Defined in:
- opal/stdlib/json.rb
Class Attribute Summary collapse
-
.create_id ⇒ Object
Returns the value of attribute create_id.
Class Method Summary collapse
- .[](value, options = {}) ⇒ Object
- .dump(obj, io = nil, limit = nil) ⇒ Object
-
.from_object(js_object, options = {}) ⇒ Object
Raw js object => opal object.
- .generate(obj, options = {}) ⇒ Object
- .parse(source, options = {}) ⇒ Object
- .parse!(source, options = {}) ⇒ Object
Class Attribute Details
.create_id ⇒ Object
Returns the value of attribute create_id
55 56 57 |
# File 'opal/stdlib/json.rb', line 55 def create_id @create_id end |
Class Method Details
.[](value, options = {}) ⇒ Object
60 61 62 63 64 65 66 |
# File 'opal/stdlib/json.rb', line 60 def self.[](value, = {}) if String === value parse(value, ) else generate(value, ) end end |
.dump(obj, io = nil, limit = nil) ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'opal/stdlib/json.rb', line 88 def self.dump(obj, io = nil, limit = nil) string = generate(obj) if io io = io.to_io if io.responds_to? :to_io io.write string io else string end end |
.from_object(js_object, options = {}) ⇒ Object
Raw js object => opal object
77 78 79 80 81 82 |
# File 'opal/stdlib/json.rb', line 77 def self.from_object(js_object, = {}) [:object_class] ||= Hash [:array_class] ||= Array `to_opal(js_object, options.map)` end |
.generate(obj, options = {}) ⇒ Object
84 85 86 |
# File 'opal/stdlib/json.rb', line 84 def self.generate(obj, = {}) obj.to_json() end |
.parse(source, options = {}) ⇒ Object
68 69 70 |
# File 'opal/stdlib/json.rb', line 68 def self.parse(source, = {}) from_object(`$parse(source)`, ) end |
.parse!(source, options = {}) ⇒ Object
72 73 74 |
# File 'opal/stdlib/json.rb', line 72 def self.parse!(source, = {}) parse(source, ) end |