Answer the question
In order to leave comments, you need to log in
Why does it return nil?
Good afternoon!
I practice OOP. Here, I decided to get the value of the key, but it gives me nil:
# frozen_string_literal: true
require 'json'
require 'net/http'
class Forex
@@response = Net::HTTP.get_response(URI.parse('https://openexchangerates.org/api/latest.json?app_id=74d160e9151c48fbafa8c5487546886d'))
@@response_body = @@response.body
@@result = JSON.parse(@@response_body, :symbolize_names => true)
attr_reader :cash, :face_value
def cash=(value)
@cash = value
end
def read
p @@result[:rates][:@cash]
end
end
money = Forex.new
money.cash = 'RUB'
money.read
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question