Skip to content

Instantly share code, notes, and snippets.

@radar
Forked from basicavisual/json-sample.json
Last active November 13, 2017 05:53
Show Gist options
  • Save radar/797e5474e6f04711fe54de06402f4933 to your computer and use it in GitHub Desktop.
Save radar/797e5474e6f04711fe54de06402f4933 to your computer and use it in GitHub Desktop.
class ApiRead
require 'open-uri'
require 'json'
attr_reader :data
def initialize(url)
# this goes fine
@data = JSON.parse(open(url).read)["data"]
end
# This works:
# a = ApiRead.new
# a = a.read
# a[0]['name']
def seed
# This doesn't. I call this like a.seed and get "undefined method `seed' for #<Array:0x00562fb82042a0>"
data.each do |record|
puts record['id']
end
end
end
reader = ApiRead.new
reader.seed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment