0
votes

I'm having trouble using the require in Ruby when I try to call the animal object.

#Classe Animal in file call animal.rb
class Animal
    def pular
        puts 'Toing! tóim! bóim! póim!'
    end

    def dormir
        puts 'ZzZzZ!'
    end
end

# Require rying to call the class Animal with arquivo app.rb
require './animal.rb'

animal = Animal.new

animal.pular

Traceback (most recent call last):
app.rb:3:in '': uninitialized constant Animal (NameError)
1
ok. my question is: I'm having trouble using the require in Ruby when I try to call the animal object. - Jacob Rodrigues

1 Answers

2
votes

You don't specify the ".rb" as Ruby will search for matching ".rb" (or ".dll" or whatever)

Also the file is in the same directory, so you would use require_relative

require_relative 'animal'