[前][次][番号順一覧][スレッド一覧]

ruby-changes:63119

From: Burdette <ko1@a...>
Date: Fri, 25 Sep 2020 17:29:13 +0900 (JST)
Subject: [ruby-changes:63119] 71f64e15b9 (master): [flori/json] Enhanced RDoc for JSON.dump (#443)

https://git.ruby-lang.org/ruby.git/commit/?id=71f64e15b9

From 71f64e15b9e23f08b8c31500efb971a61b8b2b18 Mon Sep 17 00:00:00 2001
From: Burdette Lamar <BurdetteLamar@Y...>
Date: Fri, 14 Aug 2020 00:03:12 -0500
Subject: [flori/json] Enhanced RDoc for JSON.dump (#443)

* Enhanced RDoc for JSON.dump
https://github.com/flori/json/commit/03f1699ec4

diff --git a/ext/json/lib/json/common.rb b/ext/json/lib/json/common.rb
index f6230a7..2f101e7 100644
--- a/ext/json/lib/json/common.rb
+++ b/ext/json/lib/json/common.rb
@@ -590,21 +590,33 @@ module JSON https://github.com/ruby/ruby/blob/trunk/ext/json/lib/json/common.rb#L590
     :escape_slash => false,
   }
 
-  # Dumps _obj_ as a JSON string, i.e. calls generate on the object and returns
-  # the result.
+  # :call-seq:
+  #   JSON.dump(obj, io = nil, limit = nil)
+  #
+  # Dumps +obj+ as a \JSON string, i.e. calls generate on the object and returns the result.
+  #
+  # The default options can be changed via method JSON.dump_default_options.
   #
-  # If anIO (an IO-like object or an object that responds to the write method)
-  # was given, the resulting JSON is written to it.
+  # - Argument +io+, if given, should respond to method +write+;
+  #   the \JSON \String is written to +io+, and +io+ is returned.
+  #   If +io+ is not given, the \JSON \String is returned.
+  # - Argument +limit+, if given, is passed to JSON.generate as option +max_nesting+.
   #
-  # If the number of nested arrays or objects exceeds _limit_, an ArgumentError
-  # exception is raised. This argument is similar (but not exactly the
-  # same!) to the _limit_ argument in Marshal.dump.
+  # ---
   #
-  # The default options for the generator can be changed via the
-  # dump_default_options method.
+  # When argument +io+ is not given, returns the \JSON \String generated from +obj+:
+  #   obj = {foo: [0, 1], bar: {baz: 2, bat: 3}, bam: :bad}
+  #   json = JSON.dump(obj)
+  #   json # => "{\"foo\":[0,1],\"bar\":{\"baz\":2,\"bat\":3},\"bam\":\"bad\"}"
   #
-  # This method is part of the implementation of the load/dump interface of
-  # Marshal and YAML.
+  # When argument +io+ is given, writes the \JSON \String to +io+ and returns +io+:
+  #   path = 't.json'
+  #   File.open(path, 'w') do |file|
+  #     JSON.dump(obj, file)
+  #   end # => #<File:t.json (closed)>
+  #   puts File.read(path)
+  # Output:
+  #   {"foo":[0,1],"bar":{"baz":2,"bat":3},"bam":"bad"}
   def dump(obj, anIO = nil, limit = nil)
     if anIO and limit.nil?
       anIO = anIO.to_io if anIO.respond_to?(:to_io)
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]