Hello.
I am trying to deal with simple ruby constructions. I get an array from json data:
response = JSON.parse(RESPONSE) I try to process it this way:
class GetFilm attr_accessor :group_theaters :parameter def initialize(*catalogue) title = self.get_data(catalogue, "film") @group_theaters = title end def get_data(*catalogue, parameter) @array = catalogue.length end end Sending data:
s = GetFilm.new(response.values.to_a) puts s.group_theaters For some reason, I always have catalogue.length 1, initially json looks like:
'{"catalog": { "1": { "title": "Left Behind", "theaters": ["Ukraine", "Big World"], }, "2": { "title": "Into the storm", "theaters": ["Ukraine", "Big World"], } }}' Update
RESPONSE1 = '{"catalog": { "1": { "title": "Left Behind", "theaters": ["Ukraine", "Big World"] }, "2": { "title": "Into the storm", "theaters": ["Ukraine", "Big World"] } }}' response = JSON.parse(RESPONSE1) s = GetFilm.new(response.values) And what happened: 1
puts catalogue in the get_data method shows an array in curly braces:
{"1"=>{"title"=>"Left Behind", "theaters"=>["Ukraine", "Big World"]}, "2"=>{"title"=>"Into the storm", "theaters"=>["Ukraine", "Big World"]}}