Module: Ryo::JSON
Overview
Instance Method Summary collapse
-
#from_json(path: nil, string: nil, object: Ryo::Object) ⇒ Ryo::Object, Ryo::BasicObject
Returns a Ryo object.
Instance Method Details
#from_json(path: nil, string: nil, object: Ryo::Object) ⇒ Ryo::Object, Ryo::BasicObject
Returns a Ryo object
26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ryo/json.rb', line 26 def from_json(path: nil, string: nil, object: Ryo::Object) if path && string raise ArgumentError, "Provide a path or string but not both" elsif path require "json" unless defined?(JSON) object.from JSON.parse(File.binread(path)) elsif string require "json" unless defined?(JSON) object.from JSON.parse(string) else raise ArgumentError, "No path or string provided" end end |