0

I have a file 'page.rb' containing:

require_relative "template.rb"

class MM8 < Template

end

I then have a file 'template.rb' containing:

class Template

end

Why can't I extend the MM8 class with the Template class? I get 'uninitialized constant Template (NameError)' when I try to run the program.

Zach Smith
  • 8,458
  • 13
  • 59
  • 133
  • what exactly is require_relative doing? Is it the equivalent of writing more code on a page, or is it starting a new ruby process, etc. – Zach Smith Apr 06 '15 at 10:17

1 Answers1

4

Try to call require_relative without file extension:

require_relative 'template'

You can read more about the difference between require and require_relative here.

Community
  • 1
  • 1
Alexaner Tipugin
  • 507
  • 4
  • 12
  • @ZachSmith Are you sure that `template.rb` and `page.rb` are in the same folder? Because i've just tested your code and it works fine. – Alexaner Tipugin Apr 06 '15 at 10:29
  • Ah they were, but it is working now. I hadn't saved template.rb with the actual class defined :p. Sorry, thanks for the help – Zach Smith Apr 06 '15 at 10:35