I am running my program locally through my bin folder; this is just a small CLI project. I am trying to strip and push strings into an array.
Here is my code:
require 'nokogiri'
require 'open-uri'
module BestPlaces
class Places
attr_accessor :name, :population, :places
def initialize
@places = []
end
def self.scrape_places
doc = Nokogiri::HTML(open("https://nomadlist.com/best-cities-to-live"))
places = doc.search("div.text h2.itemName")
ranks = doc.search("div.rank")
places.each{|e| @places << e.text.strip}
@places.each do |place|
i = @places.index(place)
puts "#{ranks[i].text}. #{place}"
end
end
end
class CLI
def list_places
puts "Welcome to the best places on Earth!"
BestPlaces::Places.scrape_places
end
def call
list_places
menu
goodbye
end
end
end
When I run my program, I get an error:
block in scrape_places': undefined method `<<' for nil:NilClass (NoMethodError)
Any suggestions are much appreciated.