summaryrefslogtreecommitdiff
path: root/ext/json/lib
diff options
context:
space:
mode:
authorKeith Bennett <keithrbennett@gmail.com>2020-06-30 14:07:23 -0400
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2020-09-25 17:28:42 +0900
commitc3614877d205e716bc94ad521918ad57c12ed445 (patch)
treeebd4c6259d7f4a637f52be75e7054eece9b22104 /ext/json/lib
parente1659af3724e2320e9f2f2bd7cf602686e8aa523 (diff)
[flori/json] Add `load_file` and `load_file!` methods, with tests. Fixes issue #386.
https://github.com/flori/json/commit/0be363c99b
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3581
Diffstat (limited to 'ext/json/lib')
-rw-r--r--ext/json/lib/json/common.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/ext/json/lib/json/common.rb b/ext/json/lib/json/common.rb
index 8e45b511fc7..bf2c599d0d2 100644
--- a/ext/json/lib/json/common.rb
+++ b/ext/json/lib/json/common.rb
@@ -282,6 +282,16 @@ module JSON
Parser.new(source, **(opts||{})).parse
end
+ # Parses the content of a file (see parse method documentation for more information).
+ def load_file(filespec, opts = {})
+ parse(File.read(filespec), opts)
+ end
+
+ # Parses the content of a file (see parse! method documentation for more information).
+ def load_file!(filespec, opts = {})
+ parse!(File.read(filespec), opts)
+ end
+
# :call-seq:
# JSON.generate(obj, opts = nil) -> new_string
#