Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Country
- def initialize(string)
- @country_string = string
- @country_data= @country_string.split
- @country_code = @country_data[0]
- @country_gold = @country_data[1]
- @country_silver = @country_data[2]
- @country_bronze = @country_data[3]
- @country_pop = @country_data[4]
- end
- def to_s
- return @country_string
- end
- end
- class MedalRankings
- def initialize
- @countries = Array.new
- end
- def add_country(country)
- unless country.nil? {@countries << country}; end
- end
- def to_s(n)
- for i in 0..n do
- unless n.nil? {@string << @countries[i].to_s}; end
- end
- return @string
- end
- end
- medal_rankings = MedalRankings.new
- IO.foreach('medals.txt') do |line|
- medal_rankings.add_country(Country.new(line))
- end
- puts medal_rankings.to_s(5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement