⚝
One Hat Cyber Team
⚝
Your IP:
216.73.216.133
Server IP:
185.119.109.197
Server:
Linux managedhosting.chostar.me 5.15.0-160-generic #170-Ubuntu SMP Wed Oct 1 10:06:56 UTC 2025 x86_64
Server Software:
Apache
PHP Version:
8.1.33
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
usr
/
share
/
ri
/
3.0.0
/
system
/
JSON
/
Edit File: load-i.ri
U:RDoc::AnyMethod[iI" load:ETI"JSON#load;TF:publico:RDoc::Markup::Document:@parts[o:RDoc::Markup::Paragraph; [I"DReturns the Ruby objects created by parsing the given +source+.;To:RDoc::Markup::BlankLine o:RDoc::Markup::List: @type:BULLET:@items[o:RDoc::Markup::ListItem:@label0; [o; ; [I"@Argument +source+ must be, or be convertible to, a \String:;To;; ;;[ o;;0; [o; ; [I"7If +source+ responds to instance method +to_str+, ;TI"/<tt>source.to_str</tt> becomes the source.;To;;0; [o; ; [I"6If +source+ responds to instance method +to_io+, ;TI"3<tt>source.to_io.read</tt> becomes the source.;To;;0; [o; ; [I"5If +source+ responds to instance method +read+, ;TI"-<tt>source.read</tt> becomes the source.;To;;0; [o; ; [I"SIf both of the following are true, source becomes the \String <tt>'null'</tt>:;To;; ;;[o;;0; [o; ; [I"3Option +allow_blank+ specifies a truthy value.;To;;0; [o; ; [I"MThe source, as defined above, is +nil+ or the empty \String <tt>''</tt>.;To;;0; [o; ; [I",Otherwise, +source+ remains the source.;To;;0; [o; ; [I"KArgument +proc+, if given, must be a \Proc that accepts one argument. ;TI"IIt will be called recursively with each result (depth-first order). ;TI"See details below. ;TI"MBEWARE: This method is meant to serialise data from trusted user input, ;TI"Plike from your own database server or clients under your control, it could ;TI"Hbe dangerous to allow untrusted users to pass JSON sources into it.;To;;0; [o; ; [I"MArgument +opts+, if given, contains a \Hash of options for the parsing. ;TI"@See {Parsing Options}[#module-JSON-label-Parsing+Options]. ;TI"NThe default options can be changed via method JSON.load_default_options=.;T@S:RDoc::Markup::Rule:weighti@o; ; [I"SWhen no +proc+ is given, modifies +source+ as above and returns the result of ;TI"/<tt>parse(source, opts)</tt>; see #parse.;T@o; ; [I"#Source for following examples:;To:RDoc::Markup::Verbatim; [I"source = <<-EOT ;TI"{ ;TI""name": "Dave", ;TI" "age" :40, ;TI" "hats": [ ;TI" "Cattleman's", ;TI" "Panama", ;TI" "Tophat" ;TI" ] ;TI"} ;TI" EOT ;T:@format0o; ; [I"Load a \String:;To;; [I"ruby = JSON.load(source) ;TI"Xruby # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]} ;T;0o; ; [I"Load an \IO object:;To;; [I"require 'stringio' ;TI".object = JSON.load(StringIO.new(source)) ;TI"Zobject # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]} ;T;0o; ; [I"Load a \File object:;To;; [ I"path = 't.json' ;TI"File.write(path, source) ;TI"File.open(path) do |file| ;TI" JSON.load(file) ;TI"Wend # => {"name"=>"Dave", "age"=>40, "hats"=>["Cattleman's", "Panama", "Tophat"]} ;T;0S;;i@o; ; [I"When +proc+ is given:;To;; ;;[ o;;0; [o; ; [I" Modifies +source+ as above.;To;;0; [o; ; [I"AGets the +result+ from calling <tt>parse(source, opts)</tt>.;To;;0; [o; ; [I"-Recursively calls <tt>proc(result)</tt>.;To;;0; [o; ; [I"Returns the final result.;T@o; ; [I" Example:;To;; [-I"require 'json' ;TI" ;TI"%# Some classes for the example. ;TI"class Base ;TI"" def initialize(attributes) ;TI"" @attributes = attributes ;TI" end ;TI" end ;TI"class User < Base; end ;TI"class Account < Base; end ;TI"class Admin < Base; end ;TI"# The JSON source. ;TI"json = <<-EOF ;TI"{ ;TI" "users": [ ;TI"N {"type": "User", "username": "jane", "email": "jane@example.com"}, ;TI"M {"type": "User", "username": "john", "email": "john@example.com"} ;TI" ], ;TI" "accounts": [ ;TI"Q {"account": {"type": "Account", "paid": true, "account_id": "1234"}}, ;TI"Q {"account": {"type": "Account", "paid": false, "account_id": "1235"}} ;TI" ], ;TI"8 "admins": {"type": "Admin", "password": "0wn3d"} ;TI"} ;TI" EOF ;TI"# Deserializer method. ;TI"Cdef deserialize_obj(obj, safe_types = %w(User Account Admin)) ;TI"- type = obj.is_a?(Hash) && obj["type"] ;TI"I safe_types.include?(type) ? Object.const_get(type).new(obj) : obj ;TI" end ;TI"# Call to JSON.load ;TI"(ruby = JSON.load(json, proc {|obj| ;TI" case obj ;TI" when Hash ;TI"7 obj.each {|k, v| obj[k] = deserialize_obj v } ;TI" when Array ;TI"+ obj.map! {|v| deserialize_obj v } ;TI" end ;TI"}) ;TI" pp ruby ;T;0o; ; [I"Output:;To;; [I"{"users"=> ;TI"# [#<User:0x00000000064c4c98 ;TI" @attributes= ;TI"P {"type"=>"User", "username"=>"jane", "email"=>"jane@example.com"}>, ;TI"$ #<User:0x00000000064c4bd0 ;TI" @attributes= ;TI"Q {"type"=>"User", "username"=>"john", "email"=>"john@example.com"}>], ;TI" "accounts"=> ;TI" [{"account"=> ;TI") #<Account:0x00000000064c4928 ;TI"S @attributes={"type"=>"Account", "paid"=>true, "account_id"=>"1234"}>}, ;TI" {"account"=> ;TI") #<Account:0x00000000064c4680 ;TI"U @attributes={"type"=>"Account", "paid"=>false, "account_id"=>"1235"}>}], ;TI" "admins"=> ;TI"# #<Admin:0x00000000064c41f8 ;TI"< @attributes={"type"=>"Admin", "password"=>"0wn3d"}>};T;0: @fileI" ext/json/lib/json/common.rb;T:0@omit_headings_from_table_of_contents_below0I";JSON.load(source, proc = nil, options = {}) -> object ;T0[[I"restore;To;; [ ;@�;0I"'(source, proc = nil, options = {});T@�FI" JSON;TcRDoc::NormalModule00
Simpan