Using inheritance with multiple files in Ruby
- by Preethi Jain
I am new to Ruby . I have a question with respect to using Inheritence in Ruby .
I have a class called as Doggy inside a file named Doggy.rb
class Doggy
def bark
puts "Vicky is barking"
end
end
I have written another class named Puppy in another file named puppy.rb
class Puppy < Doggy
end
puts Doggy.new.bark
I am getting this Error:
Puppy.rb:1:in `<main>': uninitialized constant Doggy (NameError)
Is it mandatory to have these classes (Doggy and Puppy ) inside a single file only?
Edited
As per the suggestions , i have tried using require and require_relative as shown , but still i am getting below Error
Puppy.rb:1:in `<main>': uninitialized constant Doggy (NameError)
class Puppy < Doggy
end
require_relative 'Doggy.rb'
puts Doggy.new.bark