summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKeith Bennett <keithrbennett@gmail.com>2020-06-30 14:07:23 -0400
committerKeith Bennett <keithrbennett@gmail.com>2020-06-30 14:07:23 -0400
commit0be363c99bb33da6b2b1b0149269b4a2e91120f7 (patch)
treebf30650ccbf6fa4034a07713ecd56151e87905e2 /lib
parentddc29e20c1c05bc96ede665ad066cbf0617a6c93 (diff)
downloadjson-0be363c99bb33da6b2b1b0149269b4a2e91120f7.tar.gz
Add `load_file` and `load_file!` methods, with tests. Fixes issue #386.
Diffstat (limited to 'lib')
-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
#