diff options
author | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2020-07-01 07:39:22 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-01 07:39:22 +0900 |
commit | e1451eda47eb4b4710a07654716b20e741ea3d58 (patch) | |
tree | bf30650ccbf6fa4034a07713ecd56151e87905e2 /lib/json/common.rb | |
parent | ddc29e20c1c05bc96ede665ad066cbf0617a6c93 (diff) | |
parent | 0be363c99bb33da6b2b1b0149269b4a2e91120f7 (diff) | |
download | json-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.rb | 10 |
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 # |