summaryrefslogtreecommitdiff
path: root/lib/json/common.rb
diff options
context:
space:
mode:
authorHiroshi SHIBATA <hsbt@ruby-lang.org>2020-07-01 07:39:22 +0900
committerGitHub <noreply@github.com>2020-07-01 07:39:22 +0900
commite1451eda47eb4b4710a07654716b20e741ea3d58 (patch)
treebf30650ccbf6fa4034a07713ecd56151e87905e2 /lib/json/common.rb
parentddc29e20c1c05bc96ede665ad066cbf0617a6c93 (diff)
parent0be363c99bb33da6b2b1b0149269b4a2e91120f7 (diff)
downloadjson-e1451eda47eb4b4710a07654716b20e741ea3d58.tar.gz
Merge pull request #387 from keithrbennett/add-load-file-methods
Add `load_file` and `load_file!` methods, with tests. Fixes issue #386.
Diffstat (limited to 'lib/json/common.rb')
-rw-r--r--lib/json/common.rb10
1 files changed, 10 insertions, 0 deletions
diff --git a/lib/json/common.rb b/lib/json/common.rb
index 991d760..bd33997 100644
--- a/lib/json/common.rb
+++ b/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
#