load_file(path) -> objectRuby 4.0 から[permalink][rdoc][edit]-
path で指定したファイルの中身を JSON 形式の文字列として読み込み、 Ruby のオブジェクトに変換します。
- [PARAM]
path: - 読み込む JSON ファイルのパスを指定します。
require "json" require "tempfile" coder = JSON::Coder.new Tempfile.create(["sample", ".json"]) do |f| f.write(coder.dump({ "name" => "Ruby" })) f.flush p coder.load_file(f.path) # => {"name"=>"Ruby"} end - [PARAM]