title: Referencing class methods and loading and iterating JSON in ruby
body: <p>I am very new to ruby, but I need to learn it for a project that I am working on. I was given some skeleton code to start with that entails loading up a JSON in the form</p>
  
  <pre><code>def self.data
    path = 'data/spells.json'
    file = File.read(path)
    JSON.parse(file)
  end
  </code></pre>
  
  <p>This a class method, and I keep trying to reference it in another method of the class, like</p>
  
  <pre><code>def names_with_same_first_letter
    spell_names = Array.new
    spells = data
    spells.each do |spell|
      if spell["Spell"].Lower
        spell_names.push(spell["Spell"].Lower)
      end
    end
    return spell_names
  end
  </code></pre>
  
  <p>maybe it's just a syntax thing, but does this method return a JSON object?
  I also tried doing self.data.each, and data.each but I keep getting a error</p>
  
  <p>also, other methods use data just fine such as </p>
  
  <pre><code>def self.random
    new(data.sample)
  end
  
  def self.effects
    data.map{|el| el["Effect"]}
  end
  </code></pre>
  
  <p>I get this error </p>
  
  <pre><code>undefined local variable or method `data' for #&lt;Spell:0x007ff04e81c130&gt;
  or
  undefined method `data' for #&lt;Spell:0x007fdd7323a1d8&gt;
  </code></pre>