Ask coding questions

← Back to all posts
Main.rb is the only file I can run
eljayuu (3)

Hello there. Newbie here. I can't see to run anything other than main.rb when I have created multiple files. I select a different file and click run, nothing happens, any suggestions greatly appreciated.

eljayuu (3)

thanks, is there specific directory I need to use? I haven't created any more folders, they are all at the same level

Zavexeon (1041)

main.rb will always run first. You can, however, tell main.rb to load other ruby files. Some examples:

require 'filename' #do not include .rb extension
require_relative 'filename.rb' #include the extension, I'd suggest this over require
load 'filename.rb' #don't forget .rb

What they do:
require and require_relative load the specified files along with the file it is in, meaning that the files are running simultaneously.

load exits out of the current file and loads only the file specified. I'd suggest this if you're just trying to load only the content of a specific file.

Note: require often does not work in replit, so use require_relative instead.

theangryepicbanana (1623)

main.rb is the only file that's run in a repl. if you want to run other files as well, use the include statement in main.rb like include "./other-file.rb"