require multiple files ruby

To require multiple files in Ruby, you can use the require method. Here's a step-by-step explanation of how to do it:

  1. Start by creating the files you want to require. Let's say you have two files: file1.rb and file2.rb.

  2. In your main Ruby file, let's call it main.rb, you can use the require method to include the contents of file1.rb and file2.rb. You can do this by adding the following lines of code at the beginning of main.rb:

require_relative 'file1'
require_relative 'file2'

The require_relative method is used to require files that are located in the same directory as your main file.

  1. Now, when you run main.rb, the contents of file1.rb and file2.rb will be included in your program, allowing you to use any classes, methods, or variables defined in those files.

It's important to note that the order in which you require the files can be significant. If file1.rb depends on something defined in file2.rb, you should require file2.rb before requiring file1.rb.

Additionally, if you're using Ruby Gems, you can use the gem method to require the necessary gems in your code.

That's it! You now know how to require multiple files in Ruby using the require method.