[flori/json] Add load_file and load_file! methods, with tests. Fixes issue #386.

0be363c99b
This commit is contained in:
Keith Bennett 2020-06-30 14:07:23 -04:00 committed by Hiroshi SHIBATA
parent e1659af372
commit c3614877d2
Notes: git 2020-09-25 17:29:14 +09:00
2 changed files with 66 additions and 0 deletions

View file

@ -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
#