vendredi 15 mai 2015

Ruby Error - undefined local variable or method

I need help with Ruby. I have a class that contains two methods. The first method opens the file, and the second method works with the data read from the file.

class Example

  def load_json(filepath)
     require 'json'
     file = File.read(path-to-file)
     file_data = JSON.parse(file)
  end

  def read_data(tag)
    load_json(tag)
    #code to read and work with the data from file_data 
  end

end

When I try that, it gives me the following error:

`read_data': undefined local variable or method `read_json'

Any help with that? Thanks! I'm a total Ruby beginner.

Aucun commentaire:

Enregistrer un commentaire