lib/cities.rb
def load_country_data(code)
      if cache_data?
        return @@cached_data[code] if @@cached_data[code]
      end

      json = File.read(path_for_country(code))
      country_data = MultiJson.load(json)

      if cache_data?
        @@cached_data[code] = country_data
      end

      country_data
    end
# This will not only load country data from a given country code
# but it will also cache if cache_data is set to true
This will not only load country data from a given country code
but it will also cache if cache_data is set to true
This will not only load country data from a given country code but it will also cache if cache_data is set to true
def load_country_data(code)
      if cache_data?
        return @@cached_data[code] if @@cached_data[code]
      end
      json = File.read(path_for_country(code))
      country_data = MultiJson.load(json)
      if cache_data?
        @@cached_data[code] = country_data
      end
      country_data
    end
def load_country_data ( code ) if cache_data? return @@cached_data [ code ] if @@cached_data [ code ] end json = File . read ( path_for_country ( code ) ) country_data = MultiJson . load ( json ) if cache_data? @@cached_data [ code ] = country_data end country_data end
This will not only load country data from a given country code
but it will also cache if cache_data is set to true
This will not only load country data from a given country code but it will also cache if cache_data is set to true
code