Read/Open Files

I have to write some code (duh) and I will have a menu that says

puts “Welcome To The Baseball Calculator”
puts “1. Show Major League winners”
puts “2. Show number of wins for a team”
puts "3. Exit "

choice = gets.chomp.to_i

if choice == 1

end

thats all I have so far…

I have a text file “winners” and a text file “teams”

how do I open/read those :confused:

Hello @sdem9,

Would be really helpful if you post your code directly in your topic.

1 Like

class SportsFiles
def initialize (teams)
@Teams = “teams.txt”
end

def read_file(teams)
file = File.open(“teams.txt”, “r”)
end

puts “Welcome To The Baseball Calculator”
puts “1. Show Major League winners”
puts “2. Show number of wins for a team”
puts "3. Exit "

choice = gets.chomp.to_i
if choice == 1

puts

end
end

Thanks @sdem9!

If you would like to read the file and to show each line:

teams = File.open('teams.txt', 'r')

teams.each do |team|
  p team
end

Thank you so much @Maniac !!

im not sure where im suppose to place in my code…

nvm I got it lol thanks for all the help